Forum Discussion

villa1980's avatar
villa1980
Resolver II
1 year ago
Solved

Replicating Power Query Formula in DAX

Simple one I imagine. I have the seen the Power Query formula which will help with my issue I have with rturning previous and next row of data. Problem is when doing this in Power Query it slows do...
  • anmolmalviya05's avatar
    1 year ago

    Hi villa1980,

    To replicate the previous and next row functionality in DAX, you can use DAX functions like EARLIER, and FILTER to create calculated columns for both the previous and next rows.

    Here’s how you can do it in DAX:

    Step 1: Create a Calculated Column for the Previous Row

    This column will get the name of the previous row based on the Index column.

     

    PreviousRow = VAR CurrentIndex = YourTable[Index] RETURN IF (     CurrentIndex = 1,     BLANK(),     CALCULATE(         MAX(YourTable[Name]),         FILTER(             YourTable,             YourTable[Index] = CurrentIndex - 1         )     ) )

     

    Step 2: Create a Calculated Column for the Next Row

    Similarly, you can create a calculated column to get the name of the next row.

     

    NextRow = VAR CurrentIndex = YourTable[Index] RETURN CALCULATE(     MAX(YourTable[Name]),     FILTER(         YourTable,         YourTable[Index] = CurrentIndex + 1     ) )

     

    Example Output

    With this setup, your table might look like this:

     

    Name Index PreviousRow NextRow

    Jeff1BLANK()Bob
    Bob2JeffIan
    Ian3BobBLANK()