Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
A_Hale_
Frequent Visitor

Pulling the previous row from a table stored as a variable in DAX

Has anybody come across the issue of returning the previous row's value from a table stored as a variable in DAX? In other words I am trying to return a new table with all of the rows of a referenced variable table (Columns 1 & 2) and an aditional column with the previous row's value (Column 3).

 

A_Hale__0-1676326889700.png

 

2 ACCEPTED SOLUTIONS
v-tangjie-msft
Community Support
Community Support

Hi @A_Hale_ ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a table.

Table 2 =
ADDCOLUMNS (
    'Table',
    "Previous Rows Value",
        CALCULATE (
            MAX ( 'Table'[Values] ),
            FILTER ( 'Table', 'Table'[Rank] = EARLIER ( 'Table'[Rank] ) - 1 )
        )
)

(3) Then the result is as follows.

vtangjiemsft_0-1676959288291.png

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

View solution in original post

Ahmedx
Super User
Super User

Can be done without creating a new table
Sample PBIX file attached
https://dropmefiles.com/Id5SI

2023-02-21_12-11-21.png2023-02-21_12-11-00.png

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.

View solution in original post

3 REPLIES 3
Ahmedx
Super User
Super User

Can be done without creating a new table
Sample PBIX file attached
https://dropmefiles.com/Id5SI

2023-02-21_12-11-21.png2023-02-21_12-11-00.png

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.

v-tangjie-msft
Community Support
Community Support

Hi @A_Hale_ ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a table.

Table 2 =
ADDCOLUMNS (
    'Table',
    "Previous Rows Value",
        CALCULATE (
            MAX ( 'Table'[Values] ),
            FILTER ( 'Table', 'Table'[Rank] = EARLIER ( 'Table'[Rank] ) - 1 )
        )
)

(3) Then the result is as follows.

vtangjiemsft_0-1676959288291.png

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

vicky_
Super User
Super User

I can't say I have any experience with these functions myself, but I think the INDEX and OFFSET functions would give you what you want, depending on the exact calculation.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.