Forum Discussion
Anonymous
4 years agoNot applicable
Need help with Measure - value before and after 0
Hi team, I have the following data: ID Date mm/dd/yyyy hh:ss Item1 Item2 1 1/1/2022 0:00 3900 ...
- 4 years ago
Hi Anonymous ,
According to your description, here's my solution.
Create two measures.
Measure1 = VAR _Pre = MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Date] = MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Date] < MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Item1] = 0 ), 'Table'[Date] ) ), 'Table'[Date] ) ), 'Table'[Item1] ) VAR _Fir = MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Date] = DATE ( YEAR ( TODAY () ), 1, 1 ) ), 'Table'[Item1] ) VAR _MAX = MAXX ( ALL ( 'Table' ), 'Table'[Date] ) VAR _LAS = MAXX ( FILTER ( 'Table', 'Table'[Date] = DATE ( YEAR ( _MAX ), MONTH ( _MAX ), DAY ( _MAX ) ) ), 'Table'[Item1] ) RETURN IF ( COUNTROWS ( FILTER ( 'Table', 'Table'[Item1] = 0 ) ) > 0, _Pre - _Fir, _LAS - _Fir )Measure2 = VAR _Pre = MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Date] = MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Date] < MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Item1] = 0 ), 'Table'[Date] ) ), 'Table'[Date] ) ), 'Table'[Item1] ) VAR _Fir = MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Date] = DATE ( YEAR ( TODAY () ), 1, 1 ) ), 'Table'[Item1] ) VAR _MAX = MAXX ( ALL ( 'Table' ), 'Table'[Date] ) VAR _LAS = MAXX ( FILTER ( 'Table', 'Table'[Date] = DATE ( YEAR ( _MAX ), MONTH ( _MAX ), DAY ( _MAX ) ) ), 'Table'[Item1] ) RETURN IF ( COUNTROWS ( FILTER ( 'Table', 'Table'[Item1] = 0 ) ) > 0, _LAS, _LAS - _Fir )Get the result.
I attach my sample below for reference.
Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
danextian
Super User
4 years agoHi Anonymous ,
- Can't this be done with calculated columns instead of measures? It would be easier to follow this route.
- If there isn’t 0 in the column, then give me difference between the latest row 0:00 h and the first row 1/1/current year 0:00. Whatis latest row and what is first row? Are you referring to the previous and current rows or to rows 1 and 7?