cancel
Showing results for
Did you mean:

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.

Helper I

## Sum Value by latest date and ID field

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
1 ACCEPTED SOLUTION
Community Support

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:

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.

11 REPLIES 11
Community Support

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:

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.

Helper I

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.

Super User

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?

Regards,
Ashish Mathur
http://www.ashishmathur.com
Helper I

Hi, you're right, I corrected this. Thanks

Super User

Hi,

PBI file attached.

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Helper I

Thanks for your suggestion, this looks good as well.

Super User

You are welcome.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Super User

Share data in a format that can be pasted in an MS Excel file.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Helper I
 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...

Super User

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

Helper I

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?

Announcements

#### Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

#### Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

#### Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors