Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
I have a table containing state changes for multiple values
time | primary_key | value | lag_value |
| 1 | A | 100 | 0 |
| 2 | B | 200 | 0 |
| 3 | A | 300 | 100 |
| 4 | B | 400 | 200 |
| 6 | A | 0 | 300 |
| 6 | B | 0 | 400 |
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?
@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])
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.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
Check out the November 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 20 | |
| 11 | |
| 10 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 34 | |
| 32 | |
| 19 | |
| 12 | |
| 10 |