Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
RaMiRo87
Frequent Visitor

sum latest value filtered by category and a date

Hi all,

 

I have a problem which might look very simple to most of you, but I don't come to a satisfying solution.

 

I have a fact table named 'InvoiceData' in which invoice data is recorded. I have individual prices per item [PurchPrice] and the total amount per item [LineAmount] in the table. Besides these values the fact table holds information about the order number, the item group, the purch unit (Kg, m, pcs etc.) and the price unit (1, 100, 1000 etc.). Now I would like to output the most recent data record for each item number in a table visual. As you can imagine, I have several data records per item number which all have a different booking date. The structure of the table visual should look like this and contain the latest record entry of each category:

 

Item IdMax Date per Item IdMax Order Nr. per Item IdMax Item Group per Item IdMax Purch Unit per Item IdMax Price Unit per Item IdMax Single Price per Item IdMax Sum per Item Id
1005001215.12.2023PO-RG12345Raw Materialsm10550
2007001417.11.2023PO-RG678910Raw MaterialsKg1004400

 

I have tried to set up various measures, but with the current measures I only get the largest entry per category, regardless of the filtering of item number and date.

 

Sorry if my english leads to misunderstandings, but it is not my first language. Please let me know on which bit of information I should be a little bit more precise.

 

Thanks in advance!

RR

2 ACCEPTED SOLUTIONS
123abc
Community Champion
Community Champion

DAX Expression: Here's a DAX expression you can use to create a new table that contains the latest record for each item number:

 

LatestRecordTable =
SUMMARIZE(
InvoiceData,
InvoiceData[Item Id],
"Max Date per Item Id", MAX(InvoiceData[BookingDate]),
"Max Order Nr. per Item Id", MAX(InvoiceData[Order Nr.]),
"Max Item Group per Item Id", MAX(InvoiceData[Item Group]),
"Max Purch Unit per Item Id", MAX(InvoiceData[Purch Unit]),
"Max Price Unit per Item Id", MAX(InvoiceData[Price Unit]),
"Max Single Price per Item Id", MAX(InvoiceData[Single Price]),
"Max Sum per Item Id", SUM(InvoiceData[LineAmount])
)

 

  1. Make sure to replace the column names with the actual column names from your "InvoiceData" table.

  2. Use the New Table in Your Visual: Once you've created the new table, you can use it in your table visual. Drag the fields from the "LatestRecordTable" into the table visual to display the latest record for each item number.

This approach utilizes the SUMMARIZE function to group the data by the item number and calculate the maximum date, order number, item group, etc., for each item number.

Ensure that your data model is properly set up, and relationships between tables are defined correctly to enable accurate filtering and aggregation of data.

By following these steps, you should be able to create a table visual that displays the most recent data record for each item number, as per your requirements.

 

 

View solution in original post

v-huijiey-msft
Community Support
Community Support

Hi @RaMiRo87 ,

 

Hope everything is going well.

 

To display the latest data for each item id in the visual, please follow these steps:

 

1. Create a measure to find the latest date for each item ID.

 

Max Date per Item Id=
CALCULATE(
     MAX(InvoiceData[BookingDate]),
     ALLEXCEPT(InvoiceData, InvoiceData[ItemId])
)

 

 

2. Create a measure to get the latest OrderNumber for each item ID.

 

Max Order Nr. per Item Id=
CALCULATE(
     LASTNONBLANK(InvoiceData[OrderNumber], 1),
     FILTER(
         InvoiceData,
         InvoiceData[BookingDate] = [Max Date per Item Id] && InvoiceData[ItemId] = MAX(InvoiceData[ItemId])
     )
)

 

 

Max Item Group per Item Id, Max Purch Unit per Item Id, Max Price Unit per Item Id, Max Single Price per Item Id, Max Sum per Item Id also repeat the steps of Max Order Nr. per Item Id.

 

3. Drag the Item ID and the created measure onto the visual object for display.

 

4. Test in your test environment.

 

If you want to learn more about these functions, please refer to the following documentation:

ALLEXCEPT function (DAX) - DAX | Microsoft Learn

LASTNONBLANK function (DAX) - DAX | Microsoft Learn

 

If you have any questions please feel free to contact me and I would be grateful if you could provide me with detailed data for testing without personal privacy.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

3 REPLIES 3
v-huijiey-msft
Community Support
Community Support

Hi @RaMiRo87 ,

 

Hope everything is going well.

 

To display the latest data for each item id in the visual, please follow these steps:

 

1. Create a measure to find the latest date for each item ID.

 

Max Date per Item Id=
CALCULATE(
     MAX(InvoiceData[BookingDate]),
     ALLEXCEPT(InvoiceData, InvoiceData[ItemId])
)

 

 

2. Create a measure to get the latest OrderNumber for each item ID.

 

Max Order Nr. per Item Id=
CALCULATE(
     LASTNONBLANK(InvoiceData[OrderNumber], 1),
     FILTER(
         InvoiceData,
         InvoiceData[BookingDate] = [Max Date per Item Id] && InvoiceData[ItemId] = MAX(InvoiceData[ItemId])
     )
)

 

 

Max Item Group per Item Id, Max Purch Unit per Item Id, Max Price Unit per Item Id, Max Single Price per Item Id, Max Sum per Item Id also repeat the steps of Max Order Nr. per Item Id.

 

3. Drag the Item ID and the created measure onto the visual object for display.

 

4. Test in your test environment.

 

If you want to learn more about these functions, please refer to the following documentation:

ALLEXCEPT function (DAX) - DAX | Microsoft Learn

LASTNONBLANK function (DAX) - DAX | Microsoft Learn

 

If you have any questions please feel free to contact me and I would be grateful if you could provide me with detailed data for testing without personal privacy.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Thank you very much for your reply and the attached solution! Sorry for the late response. I've been very sick the last couple of weeks and didn't have the chance to take a glimpse at all the responses.

123abc
Community Champion
Community Champion

DAX Expression: Here's a DAX expression you can use to create a new table that contains the latest record for each item number:

 

LatestRecordTable =
SUMMARIZE(
InvoiceData,
InvoiceData[Item Id],
"Max Date per Item Id", MAX(InvoiceData[BookingDate]),
"Max Order Nr. per Item Id", MAX(InvoiceData[Order Nr.]),
"Max Item Group per Item Id", MAX(InvoiceData[Item Group]),
"Max Purch Unit per Item Id", MAX(InvoiceData[Purch Unit]),
"Max Price Unit per Item Id", MAX(InvoiceData[Price Unit]),
"Max Single Price per Item Id", MAX(InvoiceData[Single Price]),
"Max Sum per Item Id", SUM(InvoiceData[LineAmount])
)

 

  1. Make sure to replace the column names with the actual column names from your "InvoiceData" table.

  2. Use the New Table in Your Visual: Once you've created the new table, you can use it in your table visual. Drag the fields from the "LatestRecordTable" into the table visual to display the latest record for each item number.

This approach utilizes the SUMMARIZE function to group the data by the item number and calculate the maximum date, order number, item group, etc., for each item number.

Ensure that your data model is properly set up, and relationships between tables are defined correctly to enable accurate filtering and aggregation of data.

By following these steps, you should be able to create a table visual that displays the most recent data record for each item number, as per your requirements.

 

 

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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