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
anonomi
Frequent Visitor

Difference in value of different rows in same column

I have a table with a series of values for different devices and on different dates. I would like a calcualted column to subtract each value from the previous one (to measure the increase) based on the date it was received and for each device. I've found similar questions but I couldn't apply them to my problem (as dates weren't plus 1 and there are multiple devices).  I have already added a rank as I thought that would help with the filtering, but I'm still struggling.

 

 

DeviceDateDate_RankValueDesired Value
A14/09/20191102
A15/08/2019286
A12/06/201932 
B05/03/202012212
B01/02/2020210 
     
1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @anonomi 

try

Desired Value = 
var _prevRank = CALCULATE(MIN('Table'[Date_Rank]),FILTER(ALL('Table'),'Table'[Device]=EARLIER('Table'[Device]) && 'Table'[Date_Rank] > EARLIER('Table'[Date_Rank])))
var _prevValue = LOOKUPVALUE('Table'[Value],'Table'[Device],[Device],'Table'[Date_Rank],_prevRank)
return
IF(ISBLANK(_prevValue), BLANK(), [Value]-_prevValue)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

4 REPLIES 4
az38
Community Champion
Community Champion

Hi @anonomi 

try

Desired Value = 
var _prevRank = CALCULATE(MIN('Table'[Date_Rank]),FILTER(ALL('Table'),'Table'[Device]=EARLIER('Table'[Device]) && 'Table'[Date_Rank] > EARLIER('Table'[Date_Rank])))
var _prevValue = LOOKUPVALUE('Table'[Value],'Table'[Device],[Device],'Table'[Date_Rank],_prevRank)
return
IF(ISBLANK(_prevValue), BLANK(), [Value]-_prevValue)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
anonomi
Frequent Visitor

I'm getting the error "A table of multiple values was supplied where a single value was expected". If I reduce the dataset down to a dozen devices then it does work, so I'm assuming its my data thats the issue! Would you mind explaining the LookupValue line as there are more arguments in there than I'm used to.  That might help me diagnose the issue with the dataset.

az38
Community Champion
Community Champion

@anonomi 

do you create a column or measure? it's a column

this LOOKUP is trying to find Value with selected device and the next rank which you created. maybe you have rows with the same pair device-rank


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

LOOKUPVALUE is a very slow function. Using it on a fact table will bring the calculation to a halt.

It's kind of good for small dimensions but not for a fact table.

Best
D

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.