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
How can I sum the Sales value by ID field and by latest Date of each ID?
The expected result of new measure is: 4567 (B) + 358 (A) + 453 (A) = 5378
Thank you
Sales | Deliverdate | ID |
233 | 18.01.2023 | A |
563 | 18.01.2023 | A |
453 | 01.02.2023 | A |
358 | 01.02.2023 | A |
435 | 01.04.2023 | B |
768 | 04.01.2024 | B |
547 | 11.01.2024 | B |
346 | 11.02.2024 | B |
4567 | 11.04.2024 | B |
Solved! Go to Solution.
Hi, @Dn_wemn
You can try the DAX expression below, I start by creating a measure to calculate the most recent date:
LatestDatePerID =
CALCULATE(
MAX('Table 1'[Deliverdate]),
ALLEXCEPT('Table 1', 'Table 1'[ID])
)
Then create a new measure to calculate the sum:
SumSalesByLatestDateAndID =
SUMX(
FILTER(
'Table 1',
'Table 1'[Deliverdate] = 'Table 1'[LatestDatePerID]
),
'Table 1'[Sales])
Here is my preview:
How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data)
Best Regards
Yongkang Hua
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @Dn_wemn
You can try the DAX expression below, I start by creating a measure to calculate the most recent date:
LatestDatePerID =
CALCULATE(
MAX('Table 1'[Deliverdate]),
ALLEXCEPT('Table 1', 'Table 1'[ID])
)
Then create a new measure to calculate the sum:
SumSalesByLatestDateAndID =
SUMX(
FILTER(
'Table 1',
'Table 1'[Deliverdate] = 'Table 1'[LatestDatePerID]
),
'Table 1'[Sales])
Here is my preview:
How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data)
Best Regards
Yongkang Hua
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you, this has worked.
I tried to do this in one measure, so your first measure was VAR and then I used RETURN to enter your second measure. But this has not worked. Why does it only work in 2 measures? Thx.
Hi,
The latest date of ID A is 01/02/2023. Why are you including 233 in the answer? Shouldn't the answer be 4567+358+453?
Hi, you're right, I corrected this. Thanks
Thanks for your suggestion, this looks good as well.
You are welcome.
Share data in a format that can be pasted in an MS Excel file.
Sales | Deliverdate | ID |
233 | 18.01.2023 | A |
563 | 18.01.2023 | A |
453 | 01.02.2023 | A |
358 | 01.02.2023 | A |
435 | 01.04.2023 | B |
768 | 04.01.2024 | B |
547 | 11.01.2024 | B |
346 | 11.02.2024 | B |
4567 | 11.04.2024 | B |
I dont know how to upload the pbix file though...
Hey @Dn_wemn ,
if you put it in the table, the measure should look like this:
Sales of MaxDate =
VAR _MaxDeliveryDate = CALCULATE ( MAX ( myTable[Deliverdate] ), ALLEXCEPT ( myTable, myTable[ID] ) )
VAR _Sales = CALCULATE ( SUM ( myTable[Sales] ), myTable[Deliverdate] = _MaxDeliveryDate )
RETURN
_Sales
If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
Best regards
Denis
Blog: WhatTheFact.bi
Follow me: twitter.com/DenSelimovic
Hi, thanks, your solution takes the correct max dates and ID, but the total is wrong.
I tried with SUMX but it has not worked either.
Do you know how to get the correct total which is 5378?
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
123 | |
86 | |
73 | |
57 | |
52 |
User | Count |
---|---|
201 | |
137 | |
108 | |
73 | |
68 |