March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi There.
I was hoping you could help me with this.
I have a table where I would like the difference to be calculated based on the item number
So for example Item Number 22 I'd like the difference of landed unit cost between the current item number 22 and the previous one sold to return into another column
I have created a calculated column with this formula
CalculatedDifference =
VAR PreviousItemNumber_ =
CALCULATE (
MAX ( Sheet1[Item Number] ),
Sheet1[Item Number] < EARLIER (Sheet1[Item Number]),
ALLEXCEPT ( Sheet1, Sheet1[Item Number] )
)
VAR PreviousLandedCost_ =
CALCULATE (
DISTINCT ( Sheet1[Landed Unit Cost] ),
Sheet1[Item Number] = PreviousItemNumber_,
ALLEXCEPT ( Sheet1, Sheet1[Item Number] )
)
VAR CurrentLandedCost_ = Sheet1[Landed Unit Cost]
RETURN
IF (
NOT ISBLANK ( CurrentLandedCost_ ) && NOT ISBLANK ( PreviousLandedCost_ ),
CurrentLandedCost_ - PreviousLandedCost_
But it is returning an error ;A table of multiple values was supplied where a single value was expected
Here is a copy of the table
DatePO NumberItem NumberLanded Unit Cost
Wednesday 1 January 2020 | 1 | 22 | 10 |
Thursday 2 January 2020 | 2 | 22 | 12 |
Friday 3 January 2020 | 3 | 11 | 2.86 |
Saturday 4 January 2020 | 4 | 11 | 2.85 |
Sunday 5 January 2020 | 5 | 11 | 2.84 |
Monday 6 January 2020 | 6 | 77 | 3.84 |
Tuesday 7 January 2020 | 7 | 77 | 3.89 |
Wednesday 8 January 2020 | 8 | 77 | 3.89 |
Thursday 9 January 2020 | 9 | 77 | 3.82 |
Friday 10 January 2020 | 10 | 77 | 3.75 |
Saturday 11 January 2020 | 11 | 77 | 3.75 |
Sunday 12 January 2020 | 12 | 77 | 3.75 |
Monday 13 January 2020 | 13 | 22 | 1.2 |
Tuesday 14 January 2020 | 14 | 22 | 1.2 |
Wednesday 15 January 2020 | 15 | 33 | 5 |
Thursday 16 January 2020 | 16 | 33 | 5.14 |
Friday 17 January 2020 | 17 | 33 | 5.12 |
Saturday 18 January 2020 | 18 | 33 | 5.12 |
Thank you !
Solved! Go to Solution.
HI @MaighreadL ,
Create a Calculated Column
Difference =
VAR a =
CALCULATE (
MAX ( 'Table'[Date] ),
FILTER (
'Table',
'Table'[Item Number]
= EARLIER ( 'Table'[Item Number] )
&& 'Table'[Date]
< EARLIER ( 'Table'[Date] )
)
)
VAR b =
CALCULATE (
MAX ( 'Table'[Unit Cost] ),
FILTER (
'Table',
'Table'[Item Number]
= EARLIER ( 'Table'[Item Number] )
&& 'Table'[Date] = a
)
)
RETURN
IF (
b
<> BLANK (),
'Table'[Unit Cost] - b
)
Regards,
Harsh Nathani
Appreciate with a Kudos!! (Click the Thumbs Up Button)
Did I answer your question? Mark my post as a solution!
HI @MaighreadL ,
Create a Calculated Column
Difference =
VAR a =
CALCULATE (
MAX ( 'Table'[Date] ),
FILTER (
'Table',
'Table'[Item Number]
= EARLIER ( 'Table'[Item Number] )
&& 'Table'[Date]
< EARLIER ( 'Table'[Date] )
)
)
VAR b =
CALCULATE (
MAX ( 'Table'[Unit Cost] ),
FILTER (
'Table',
'Table'[Item Number]
= EARLIER ( 'Table'[Item Number] )
&& 'Table'[Date] = a
)
)
RETURN
IF (
b
<> BLANK (),
'Table'[Unit Cost] - b
)
Regards,
Harsh Nathani
Appreciate with a Kudos!! (Click the Thumbs Up Button)
Did I answer your question? Mark my post as a solution!
@MaighreadL I'm sure @harshnathani solution will work, I didn't look at it but it can have performance implications on a large dataset. I would add a measure using the following DAX expression:
Measure =
VAR __tbl = ALL ( 'Table'[Id], 'Table'[DatePO] )
VAR __prevDate = CALCULATE ( MAX ( 'Table'[DatePO] ), FILTER ( __tbl, 'Table'[DatePO] < MAX ( 'Table'[DatePO] ) ) )
RETURN
CALCULATE ( SUM ( 'Table'[Amount] ), __tbl, 'Table'[DatePO] = __prevDate)
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
114 | |
76 | |
57 | |
52 | |
44 |
User | Count |
---|---|
165 | |
116 | |
63 | |
57 | |
50 |