Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I need a measure that gives me the quantity of the last order line (max line number) per ORDERNUMBER.
For order S45879412 the max measure should return 70, and for S45879555 return 75.
Solved! Go to Solution.
HI @bmpi,
You can try to use the following measure formula if it helps:
SumQty =
VAR summary =
ADDCOLUMNS (
SUMMARIZE ( ALLSELECTED ( Sheet1 ), [Order], "LastLine", MAX ( Sheet1[Line] ) ),
"LastLineQTY",
CALCULATE (
SUM ( Sheet1[QTY] ),
FILTER (
ALLSELECTED ( Sheet1 ),
Sheet1[Line] = [LastLine]
&& Sheet1[Order] = [Order]
)
)
)
RETURN
SUMX ( summary, LastLineQTY )
Regards,
Xiaoxin Sheng
@bmpi , I have blog on the same topic
https://amitchandak.medium.com/power-bi-get-the-last-latest-value-of-a-category-d0cf2fcf92d0
Last Status = var _max = maxx(filter(ALLSELECTED(Data), Data[Ordernumber] = Max(Data[Ordernumber])), Data[Line])
return
CALCULATE(Sum(Data[quantity]), filter((Data) , Data[Line] =_max))
Thank you that worked!
Must admit, I don't quite get how that first part works.
Last Status = var _max = maxx(filter(ALLSELECTED(Data), Data[Ordernumber] = Max(Data[Ordernumber])), Data[Line])
If I write it like this, I still get it to work:
var _max = maxx(Data, Data[Line])
Can you explain the difference? (it is probably a good reason :))
@bmpi , The second one will work if do not take ID ,
I Check and did not work the same for me
Also, you need one additional measure to get the correct grand total
Last Status = Var _max = maxx(filter( ALLSELECTED(Data), Data[Ordernumber] = max(Data[Ordernumber]) ),Data[Line])
return
CALCULATE(sum(Data[quantity]), filter( (Data), Data[Ordernumber] = max(Data[Ordernumber]) && Data[Line] =_max))
Sum Last Qty = sumx(VALUES(Data1[Ordernumber]) , [Last Qty])
I actually do not get the sum correct.
I get 76 when I should get 43.
My testdata looks like this:
Order | Line | QTY | ||
45879412 | 1 | 5 | ||
45879412 | 2 | 8 | ||
45879555 | 2 | 19 | ||
45879555 | 1 | 5 | ||
45879333 | 2 | 5 | ||
45879333 | 3 | 2 | ||
45879444 | 1 | 5 | ||
45879444 | 3 | 14 | ||
45879444 | 2 | 5 |
Formula looks like this:
HI @bmpi,
You can try to use the following measure formula if it helps:
SumQty =
VAR summary =
ADDCOLUMNS (
SUMMARIZE ( ALLSELECTED ( Sheet1 ), [Order], "LastLine", MAX ( Sheet1[Line] ) ),
"LastLineQTY",
CALCULATE (
SUM ( Sheet1[QTY] ),
FILTER (
ALLSELECTED ( Sheet1 ),
Sheet1[Line] = [LastLine]
&& Sheet1[Order] = [Order]
)
)
)
RETURN
SUMX ( summary, LastLineQTY )
Regards,
Xiaoxin Sheng
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
105 | |
105 | |
88 | |
73 | |
66 |
User | Count |
---|---|
124 | |
113 | |
98 | |
80 | |
72 |