Forum Discussion
Total as difference on multiple levels
- Anonymous4 years ago
Hi Nijlal01
I have a test by your sample and dax code. I find that your use AllSELECTED and ALL function in your X and Y code. Due to you use hierachy level in your Matrix, I think you don't need to use these two function to get data. But you need to use ALL function to get Max Date.
Update Code:
Difference = VAR _MaxDate = MAXX ( ALL ( Sheet1 ), Sheet1[PublishDate] ) VAR _x = CALCULATE ( SUM ( Sheet1[QTY] ), FILTER ( Sheet1, Sheet1[PublishDate] < _MaxDate ) ) VAR _y = CALCULATE ( SUM ( Sheet1[QTY] ), FILTER ( Sheet1, Sheet1[PublishDate] = _MaxDate ) ) RETURN IF ( HASONEFILTER ( Sheet1[PublishDate] ), SUM ( Sheet1[QTY] ), _x - _y )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Greg_Deckler ,
Thanks for the help! See data below:
PublishDate | Product | ShipTo | WkNr | QTY |
| 1-1-2021 | 100001 | A | 1 | 10 |
| 1-1-2021 | 100001 | B | 1 | 15 |
| 1-1-2021 | 100001 | B | 2 | 10 |
| 1-1-2021 | 100002 | A | 1 | 15 |
| 1-1-2021 | 100002 | A | 2 | 20 |
| 1-1-2021 | 100002 | B | 2 | 20 |
| 2-1-2021 | 100001 | A | 1 | 15 |
| 2-1-2021 | 100001 | A | 1 | 25 |
| 2-1-2021 | 100001 | B | 2 | 20 |
| 2-1-2021 | 100002 | B | 2 | 15 |
| 2-1-2021 | 100002 | A | 2 | 30 |
| 2-1-2021 | 100002 | A | 1 | 10 |
Hi Nijlal01
I have a test by your sample and dax code. I find that your use AllSELECTED and ALL function in your X and Y code. Due to you use hierachy level in your Matrix, I think you don't need to use these two function to get data. But you need to use ALL function to get Max Date.
Update Code:
Difference =
VAR _MaxDate =
MAXX ( ALL ( Sheet1 ), Sheet1[PublishDate] )
VAR _x =
CALCULATE (
SUM ( Sheet1[QTY] ),
FILTER ( Sheet1, Sheet1[PublishDate] < _MaxDate )
)
VAR _y =
CALCULATE (
SUM ( Sheet1[QTY] ),
FILTER ( Sheet1, Sheet1[PublishDate] = _MaxDate )
)
RETURN
IF ( HASONEFILTER ( Sheet1[PublishDate] ), SUM ( Sheet1[QTY] ), _x - _y )
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Nijlal014 years agoHelper I
You are a genius! Thanks 😄