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.
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.
Solved! Go to 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:
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.
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] )
)
)
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.
Hi @v-yingjl ,
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:
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.
@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])
))
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
99 | |
80 | |
70 | |
59 |
User | Count |
---|---|
149 | |
114 | |
107 | |
89 | |
67 |