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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Qazybek
Frequent Visitor

How to refer to the previous row?

Capture.PNGDear friends,

 

How can I refer to the previous row in Power BI this way?

Thank you

 

 

 

1 ACCEPTED SOLUTION
Chihiro
Solution Sage
Solution Sage

If doing in DAX Calculated column, something like below.

Column =
VAR calc =
    CALCULATE (
        MAX ( [Amount] ),
        FILTER ( Table, [Index] = ( EARLIER ( [Index] ) - 1 ) )
    )
        * (
            1
                + CALCULATE (
                    MAX ( [Rate] ),
                    FILTER ( Table, [Index] = ( EARLIER ( [Index] ) - 1 ) )
                )
        )
RETURN
    IF ( ISBLANK ( calc ), 1000, calc )

View solution in original post

5 REPLIES 5
Chihiro
Solution Sage
Solution Sage

If doing in DAX Calculated column, something like below.

Column =
VAR calc =
    CALCULATE (
        MAX ( [Amount] ),
        FILTER ( Table, [Index] = ( EARLIER ( [Index] ) - 1 ) )
    )
        * (
            1
                + CALCULATE (
                    MAX ( [Rate] ),
                    FILTER ( Table, [Index] = ( EARLIER ( [Index] ) - 1 ) )
                )
        )
RETURN
    IF ( ISBLANK ( calc ), 1000, calc )
Anonymous
Not applicable

Hi @Chihiro,

 

Thank you for your answer. Is it possible to write the formula inside "Amount" column in DAX?

Can't think of way to do it in DAX.

 

 

Let me think on it.

Chihiro
Solution Sage
Solution Sage

Depends on where you want to do the calculation.

 

In Query Editor ("M"): Replace #"PreviousStep" with acutal previous step name

= try #"PreviousStep"{[Index]-2}[Amount] * (1 + #"PreviousStep"{[Index]-2}[Rate]) otherwise 1000

Since row index is 0 based, and your index column is 1 based, you'd subtract 2 from index column value to obtain row index of previous row.

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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