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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

On change data obtain with DAX

I have a table containing state changes for multiple values

time

primary_keyvaluelag_value
1A1000
2B2000
3A300100
4B400200
6A0300
6B0400


I can easily calculate the value of the last state with the following formula:

 

 

WantedVal =
var vDate = MAX('Table'[time])
Return
CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'[time]),'Table'[time]<= vDate))-CALCULATE(SUM('Table'[lag_value]),FILTER(ALL('Table'[time]),'Table'[time]<= vDate))

 

 


However, I'd rather not create all the lags as I have multiple value variables.

I've tried to recreate this measure without the lag, but I fail to make it work in a context of primary_key + time, primary_key or time.
For instance, the following measure works in primary_key + time but not in a context only using time:

 

 

no_lag_value = 
VAR vDate = MAX('Table'[time])
RETURN
CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'[time]),'Table'[time]<= vDate)) -  SUMX(  FILTER(ALLSELECTED('Table'),'Table'[group] in VALUES('Table'[group])),CALCULATE(SUM('Table'[value]),'Table'[time]<vDate))

 

 


Summarising, is there a way to reproduce WantedVal without using lag_value?

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous ,

new column =
var _1 = maxx(filter(Table1, Table1[time] < earlier(Table1[time]) && Table1[primary_key] =earlier(Table1[primary_key]) ), [time])
return
maxx(filter(Table1, Table1[time] =_1 && Table1[primary_key] =earlier(Table1[primary_key]) ), [value])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hello @amitchandak ,
I don't want a column with the lag (I could add it in the m query). I have around ten values on change, and more can come making it hard to sustain. For that reason, I'm looking for a measure that I can generalise if needed.

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.