Skip to main content
Solved

Is it possible to compare one row with another in an OLAP Table or other element?

  • September 17, 2021
  • 2 replies
  • 4 views

Forum|alt.badge.img+11

data exampleThe logic is as follows:

  • if a category repeats (like C1), then:
  • for each category, calculate the date difference (DATEDIFF) between "closed at" date of a row with "closed" status and the "opened at" date of the rows with an "open" status.

 

The objective is to have an extra column to the right, with these values:

Difference (in days)

18 (DATEDIFF(dd,17.09.2021,30.08.2021)

16 (DATEDIFF(dd,15.09.2021,30.08.2021)

N/A (because its status is closed)

N/A (because the category doesn't repeat)

N/A (because the category doesn't repeat)

 

Suggestions?

Best answer by janpeter.van.d

Hi @luis.magal,

 

Not sure if the code below will work, since you will use a pull-up function only partially in your formula, but it is worth a try:

 

CASE

WHEN "<TABLE_NAME>"."status" = 'open'

THEN DATEDIFF(DD,

"<TABLE_NAME>"."opened at",

PU_LAST(DOMAIN("<TABLE_NAME>"."category") , "<TABLE_NAME>"."closed at" , "<TABLE_NAME>"."status" = closed)

)

ELSE NULL

END

 

These are the steps you take:

  1. The code checks if the status is open for that row
  2. If so, you will do a datediff, as you already suggested. First you take the 'opened at' date, secondly, you create a Pull-up fuction, that looks for all the categories in the 'category' column. for each category, it will take the last value of the 'closed at' column, where 'status' is 'closed'.
  3. If the status is not open, it will return null

2 replies

janpeter.van.d
Level 12
Forum|alt.badge.img+26
  • Level 12
  • 496 replies
  • Answer
  • September 17, 2021

Hi @luis.magal,

 

Not sure if the code below will work, since you will use a pull-up function only partially in your formula, but it is worth a try:

 

CASE

WHEN "<TABLE_NAME>"."status" = 'open'

THEN DATEDIFF(DD,

"<TABLE_NAME>"."opened at",

PU_LAST(DOMAIN("<TABLE_NAME>"."category") , "<TABLE_NAME>"."closed at" , "<TABLE_NAME>"."status" = closed)

)

ELSE NULL

END

 

These are the steps you take:

  1. The code checks if the status is open for that row
  2. If so, you will do a datediff, as you already suggested. First you take the 'opened at' date, secondly, you create a Pull-up fuction, that looks for all the categories in the 'category' column. for each category, it will take the last value of the 'closed at' column, where 'status' is 'closed'.
  3. If the status is not open, it will return null

Forum|alt.badge.img+11
  • Author
  • Level 3
  • 2 replies
  • September 23, 2021

Hi @luis.magal,

 

Not sure if the code below will work, since you will use a pull-up function only partially in your formula, but it is worth a try:

 

CASE

WHEN "<TABLE_NAME>"."status" = 'open'

THEN DATEDIFF(DD,

"<TABLE_NAME>"."opened at",

PU_LAST(DOMAIN("<TABLE_NAME>"."category") , "<TABLE_NAME>"."closed at" , "<TABLE_NAME>"."status" = closed)

)

ELSE NULL

END

 

These are the steps you take:

  1. The code checks if the status is open for that row
  2. If so, you will do a datediff, as you already suggested. First you take the 'opened at' date, secondly, you create a Pull-up fuction, that looks for all the categories in the 'category' column. for each category, it will take the last value of the 'closed at' column, where 'status' is 'closed'.
  3. If the status is not open, it will return null

It worked! Thank you!