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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Previous Row Value Dax

Hello Everyone,

 

I need to get previous row value and need help. I have a calculated measure like that;

 

RunningSum=

CALCULATE(

SUM( 'TABLE'[sales] ),

FILTER(

ALLSELECTED('TABLE'),

'TABLE'[date]<=MAX('TABLE'[date])

))

 

And I'm trying to create a calculated column as below but its not working.

 

VAR locations= 'TABLE'[store]

VAR dates= 'TABLE'[date]

return

CALCULATE(

MAX(RunningSum),

FILTER('TABLE',

'TABLE'[store]=locations && 'TABLE'[date]< dates

))

 

Appreciate your help.

1 ACCEPTED SOLUTION

Hi @Anonymous ,

Thanks for your provided details. Since Dax is calculated based on column value not row value, the last row in your picture cannot achieved if there is no continued date after 2020/1/31 because it add a new row in your dataset.

Basically the previous row measure will be like this:

Previous row value =
CALCULATE (
    [RunningSum],
    FILTER (
        ALL ( 'Table' ),
        'Table'[Date]
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER ( ALL ( 'Table' ), 'Table'[Date] < SELECTEDVALUE ( 'Table'[Date] ) )
            )
    )
)

You will get the result in the table visual:

previous value.png

Attached a new sample file in the below, hopes to help you.

 

Best Regards,
Yingjie Li

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

4 REPLIES 4
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

Based on your first measure, you are trying to calculate a cumulative value which should get the previous row value.

You can try to create this calculated column:

Column = 
CALCULATE (
    SUM ( 'Table'[sales] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[store] = EARLIER ( 'Table'[store] )
            && 'Table'[date] <= EARLIER ( 'Table'[date] )
    )
)

re.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Yingjie Li

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

Anonymous
Not applicable

Hi @v-yingjl  ,

 

Firstly, i appreciate for your answers. I think i should give some detail about what i want to get.
I have a value and RunningSum measure which I've created before as you can see below.
So i want to get Previous Row Value using RunningSum measure.
 
img.png
 
Thanks.

Hi @Anonymous ,

Thanks for your provided details. Since Dax is calculated based on column value not row value, the last row in your picture cannot achieved if there is no continued date after 2020/1/31 because it add a new row in your dataset.

Basically the previous row measure will be like this:

Previous row value =
CALCULATE (
    [RunningSum],
    FILTER (
        ALL ( 'Table' ),
        'Table'[Date]
            = CALCULATE (
                MAX ( 'Table'[Date] ),
                FILTER ( ALL ( 'Table' ), 'Table'[Date] < SELECTEDVALUE ( 'Table'[Date] ) )
            )
    )
)

You will get the result in the table visual:

previous value.png

Attached a new sample file in the below, hopes to help you.

 

Best Regards,
Yingjie Li

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

amitchandak
Super User
Super User

@Anonymous , power bi do not support the previous row. So based on data we need to calculate. like you need till the previous date

 

Try with date table

 

RunningSum= // current
CALCULATE(
SUM( 'TABLE'[sales] ),
FILTER(
ALLSELECTED('Date'),
'Date'[date]<=MAX('Date'[date])
))


previous RunningSum= //previous
CALCULATE(
SUM( 'TABLE'[sales] ),
FILTER(
ALLSELECTED('Date'),
'Date'[date]<MAX('Date'[date])
))

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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