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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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