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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

DAX / Inventory Data: Sum in the context of last date available

Hello everyone! I've long researched for a solution for this problem and never found it... maybe someone can help me solve this once and for all 🙏

I want to know how can I create a measure that sums units in inventory, but also considering the max(Date) avaliable in any given context.

 

Below is the dummy data table, with:
- A list of brands (A, B and C)

- Dates in which their is any stock data recorded for this brands (some with daily data ,some with a lot of data gaps)

- The storage facility in with that stock is stored (Some brands have only one, others more)

- The product ID

- And the metric, the units of stock of that product in that facility, on that date given, for its respective brand.

 

- If I create a measure in PowerBI like SUM(Units), it will show incorrect data if I want to show more than one date at a time. It would only work if my STOCK table had only the last "snapshot" of inventory, but I need to be able to see how stock was on previous periods as well.

- If I create a measure that calculates the SUM of units for the last date available (see DAX code below), then it doesn't sum up correctly when I add breakdowns. Why? because I don't have data for all products, on all storage facilities, and all the calendar dates possible. So when one brand has a more updated inventory_date, it only shows the SUM for that brand.

 

CALCULATE(SUM('- STOCK'[units_in_stock]),'- STOCK'[Inventory_Date]=MAX('- STOCK'[Inventory_Date]))

 

 

Is the only solution available, to create all "nulls" possible for all my calendar dates, posible skus and storage facilities, or is there another way around?

Thank you in advance!

Marina

 

Sample data:

brandInventory_Datestorage_facilityProduct_IDUnits in stock
A2/5/2023Own112233229
A2/5/2023FBA112233273
A3/5/2023Own112233228
A3/5/2023FBA112233350
A4/5/2023Own112233228
A4/5/2023FBA112233342
B29/4/2023Main112244811
B29/4/2023Main3344551335
B30/4/2023Main112244801
B30/4/2023Main3344551234
B1/3/2023Main112244742
B1/3/2023Main3344551233
B8/3/2023Main1122441005
B8/3/2023Main3344551231
B15/3/2023Main1122441002
B15/3/2023Main3344551220
C22/3/2023FBM3333331413
C29/3/2023FBM3333331213
C5/4/2023FBM333333902
C1/3/2023One2222222234
C22/3/2023One2222221384
C5/4/2023One222222

861

1 REPLY 1
lbendlin
Super User
Super User

To report on things that are not there you need to use disconnected tables and/or crossjoins

In your case you need a disconnected calendar table, dimension tables for product, facilty and brand, and measures to calculate the correspondig inventory level for the combinations of these columns.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors