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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
mweschenburg
Frequent Visitor

Periodic Snapshot with Missing Periods

I have inventory fact table with periodic snapshots sliced by several dimensions.  Multiple organizations (Entity) upload inventory weekly/monthly (fiscal Date) and each monthly inventory can include more than one record (Growth Center).  Each entity may upload their inventory on different dates and sometimes whole periods are missed.

 

Screenshot #1:  Report model with the relevant Organization (Entity), Fiscal Date, and Growth Center dimensions.  The actual model includes additional dimensions, but they should behave similarly to Growth Center.

 

Screenshot #2:  Top visual shows the months (and specific dates) that each entity uploaded an inventory snapshot.  The dates look weird because they are based on our fiscal calendar.  Some months are missing from an entity, in which case I want to use the previous inventory snapshot for that entity.  The circled dates and arrows indicate what snapshot dates should be used.  For Entity=3340, I want to repeat the 20210731 inventory for August.  And for Entity=3586, I want to use the 20211030 inventory for November and December.

 

I started with a DAX sample from DAX Patterns site (https://www.daxpatterns.com/semi-additive-calculations/); using the “Closing Ever” measure.  I further simplified the DAX until I ended up with this:

 

Latest Prior Date =

VAR MaxDateReportContext = MAX('Fiscal Date'[Fiscal Date ID])

VAR MaxInventoryDatePerEntity =

GROUPBY(

FILTER('Inventory Balance', 'Inventory Balance'[Inventory Date ID] <= MaxDateReportContext),

'Inventory Balance'[Organization ID], "Inventory Date ID",

MAXX(CURRENTGROUP(), 'Inventory Balance'[Inventory Date ID])

)

RETURN MAXX(MaxInventoryDatePerEntity, [Inventory Date ID])

 

The bottom visual shows the inventory quantities and has the same monthly gaps. 

 

Latest Prior Quantity =

VAR MaxDateReportContext = MAX('Fiscal Date'[Fiscal Date ID])

VAR MaxInventoryDatePerEntity =

GROUPBY(

FILTER('Inventory Balance', 'Inventory Balance'[Inventory Date ID] <= MaxDateReportContext),

'Inventory Balance'[Entity], "Inventory Date ID",

MAXX(CURRENTGROUP(), 'Inventory Balance'[Inventory Date ID])

)

VAR FilterInventory =

TREATAS(MaxInventoryDatePerEntity, 'Inventory Balance'[Entity], 'Inventory Balance'[Inventory Date ID])

RETURN SUMX(FilterInventory, [Quantity On Hand])

 

These measures are not entirely wrong, but don’t fill in the missing months as expected.  I think I need to tell the measures to ignore the context filters from the month columns in the matrix, but not sure how to do that.  I tried many variations of ALL(), ALLEXCEPT(), LASTNONBLANK() but really not sure where they need to be inserted.

 

Screenshot #3:  My desired result, which curiously uses the exact same DAX measures.  I got it to work by disabling the relationship between Inventory Balance and Fiscal Date, which sort of confirms my suspicion about why the results in Screenshot #3 don’t work.

 

Can someone suggest how to disable/ignore the Fiscal Date relationship in the DAX measure instead of in the report model?

 

PBIX file is available here:  https://www.dropbox.com/s/hwu5p02ts1m1cf5/Inventory.pbix?dl=0

 

Screenshot #1

mweschenburg_0-1644375926784.png

 

Screenshot #2

mweschenburg_1-1644375926801.png

 

Screenshot #3

mweschenburg_2-1644375926822.png

 

 

2 REPLIES 2
mweschenburg
Frequent Visitor

Unfortunately not the solution.  Using the revised measure with ALL(), the monthly quantity matrix looks like...

 

mweschenburg_0-1644379599519.png

 

amitchandak
Super User
Super User

@mweschenburg , Try with all

 

Latest Prior Quantity =

VAR MaxDateReportContext = MAX('Fiscal Date'[Fiscal Date ID])

VAR MaxInventoryDatePerEntity =

GROUPBY(

FILTER(all('Inventory Balance'), 'Inventory Balance'[Inventory Date ID] <= MaxDateReportContext),

'Inventory Balance'[Entity], "Inventory Date ID",

MAXX(CURRENTGROUP(), 'Inventory Balance'[Inventory Date ID])

)

VAR FilterInventory =

TREATAS(MaxInventoryDatePerEntity, 'Inventory Balance'[Entity], 'Inventory Balance'[Inventory Date ID])

RETURN SUMX(FilterInventory, [Quantity On Hand])

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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