Forum Discussion
ahsan005
3 years agoFrequent Visitor
Compare Previous Two Rows with a Current Row using DAX
Hi Everyone, I have to create a new column and am trying to compare rows in a single column when a particular value exists in any of the rows. For e.g. If Table[category] = "Site Down", then ...
- 3 years ago
There are newer DAX functions that are similar to SQL's LAG. For example, OFFSET:
IsSiteDown = VAR Summary = SUMMARIZE ( Table2, Table2[sitename], Table2[category], Table2[firstoccurrence] ) VAR Prev1Cat = MAXX ( OFFSET ( -1, Summary, ORDERBY ( Table2[firstoccurrence] ), PARTITIONBY ( Table2[sitename] ) ), Table2[category] ) VAR Prev2Cat = MAXX ( OFFSET ( -2, Summary, ORDERBY ( Table2[firstoccurrence] ), PARTITIONBY ( Table2[sitename] ) ), Table2[category] ) VAR Result = IF ( Table2[category] = "Site Down" && Prev1Cat = "Low Voltage" && Prev2Cat = "AC Mains Failure", "Yes", "No" ) RETURN Result
ahsan005
3 years agoFrequent Visitor
AlexisOlson Yes It works. Thanks a lot!
Could you please explain the use of MAXX? Could it be any other iterator?
AlexisOlson
3 years agoSuper User
OFFSET returns a row and I want a specific column from that row, so I selected it using MAXX. There isn't anything special about MAXX; you could use other iterators too. SELECTCOLUMNS would work too and is probably more intuitive.