Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello,
I am working on a project where is needed the last and second last readings for an asset and get the difference between values, so we can make some decisions afteerwards based on the difference. I created two calculated columns, but they are very expensive, especially the secondlastvalue formula. I shared a screenshot with the readings (value), dates (taken_date), where(taken_at_location), reading type (UT Reading Minimum) and asset. Also, the formulas for my last and second last values.
latestvalue =
VAR last_date =
CALCULATE ( MAX ( Readings[taken_date] ), Readings[value] <> BLANK () )
RETURN
CALCULATE (
SELECTEDVALUE ( Readings[value] ),
Readings[taken_date] = last_date
)
You can see that for each location there are two readings (now they are the same, but is not the standard) for two dates. Can somebody take a look at the formulas, maybe there is another way to get those values?
Much appreciated!
Solved! Go to Solution.
Hi daXtreme, I manipulated the formulas to work, it is a bit faster. I like using the lastdate and secondlastdate measures. Thank you for your input.
Tried to format it in DAX Formatter and get the error at Return
Here are some measures you can try... Measures, not calculated colums.
// Hidden helper measure; easier to debug
[_LatestDate] =
var Output =
CALCULATE(
MAX( Readings[taken_date] ),
keepfilters(
not isblank( Readings[value] )
)
return
Output
// Hidden helper measure
[_SecondLatestDate] =
var LatestDate = [_LatestDate]
var Output =
CALCULATE (
MAX ( Readings[taken_date] ),
keepfilters(
Readings[taken_date] < LatestDate
)
)
return
Output
// This works on the assumption that
// there will only be at most 1 value
// for the LatestDate. If there are
// many, BLANK will be returned since
// this is the behaviour of SELECTEDVALUE.
// Same applies to the second measure.
[LatestValue] =
VAR LastestDate = [_LatestDate]
var Output =
CALCULATE(
SELECTEDVALUE( Readings[value] ),
keepfilters(
Readings[taken_date] = LatestDate
)
)
return
Output
[SecondLatestValue] =
VAR SecondLastestDate = [_SecondLatestDate]
var Output =
CALCULATE (
SELECTEDVALUE ( Readings[value] ),
keepfilters(
Readings[taken_date] = SecondLatestDate
)
)
return
Output
[Difference] = [LatestValue] - [SecondLatestValue]
Hi daXtreme, I manipulated the formulas to work, it is a bit faster. I like using the lastdate and secondlastdate measures. Thank you for your input.
Hi daXtreme, for some reason I get an error regarding the Return syntax!?
_LatestDate] = var Output = CALCULATE( MAX( Readings[taken_date] ), keepfilters( not isblank( Readings[value] ) ) return Output
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
23 | |
10 | |
10 | |
9 | |
7 |