The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
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.
Device | Date | Date_Rank | Value | Desired Value |
A | 14/09/2019 | 1 | 10 | 2 |
A | 15/08/2019 | 2 | 8 | 6 |
A | 12/06/2019 | 3 | 2 | |
B | 05/03/2020 | 1 | 22 | 12 |
B | 01/02/2020 | 2 | 10 | |
Solved! Go to Solution.
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)
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)
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.
User | Count |
---|---|
15 | |
13 | |
8 | |
6 | |
6 |
User | Count |
---|---|
27 | |
19 | |
12 | |
9 | |
7 |