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

Be 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

Reply
JKarrick
Frequent Visitor

Inventory Needs to Be Zero Instead of Last Value

The daily inventory snapshot by material only includes rows when there is inventory. Currently the inventory in an Analysis Services tabular cube is overstated at the month level because it shows the last value for the time period. In the example below, material 392338 shows 21 for Dec 2023. However, when expanded to the day level the last day with inventory is Dec 20.  Instead, the Dec 2023 total should be zero. The current DAX calculation is below. Any suggestions on how to make it return a zero for any dates after Dec 20 rather  than showing 21? 

 

JKarrick_0-1705521576182.png

 

JKarrick_1-1705521710670.png

Current DAX for Inventory:

VAR SelectedPeriods =
VALUES ( 'Date'[date_key] )

VAR SelectedPeriodsSS =
VALUES ( Inventory[INVENTORY_LEVEL_DATE_DIM_KEY] )

VAR MaxPeriodID =
CALCULATE (
MAX ( Inventory[INVENTORY_LEVEL_DATE_DIM_KEY] ),
ALL ( 'Inventory' ),
SelectedPeriods,
SelectedPeriodsSS
)
RETURN
CALCULATE (
SUM ( Inventory[BATCH_WEIGHT_TONS] ),
Inventory[INVENTORY_LEVEL_DATE_DIM_KEY] = MaxPeriodID
)

 

 

5 REPLIES 5
v-yaningy-msft
Community Support
Community Support

Hi, @JKarrick 

Based on your description, is this what you need?

1.When the matrix is not expanded, change the value corresponding to 392338 in row Dec 2023 to 0.

2.After expanding the matrix, change all the values after 12/21 to 0 instead of blank values.

You can share the pbix file without sensitive data or the data and any related measures.

 

vyaningymsft_0-1705557504097.png

 

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!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Hi @v-yaningy-msft,

Thank you for the reply. You are correct in the desired results.

1. Yes, when the matrix is not expanded, change the value corresponding to 392338 in row Dec 2023 to 0.

2. Yes, after expanding the matrix, change all the values after 12/21 to 0 instead of blank values.

 

The pbix file data source is an analysis services cube and I'm using Tabular Editor to build the model so that's where the DAX code resides for inventory tons. The cube will be accessed by users via PBI and Excel, so I'm hoping to modify the model so any tool shows the desired results. The table below contains the sample data. In the model there is a also a date dimension that the inventory date from the fact table maps to. 

 

DateMaterial NumberInventory Tons
12/1/20233443061203
12/1/202339233824
12/2/20233443061203
12/2/202339233824
12/3/20233443061203
12/3/202339233824
12/4/20233443061163
12/4/202339233824
12/5/20233443061102
12/5/202339233824
12/6/20233443061082
12/6/202339233824
12/7/20233443061082
12/7/202339233824
12/8/20233443061082
12/8/202339233824
12/9/20233443061082
12/9/202339233824
12/10/20233443061082
12/10/202339233824
12/11/20233443061082
12/11/202339233824
12/12/20233443061082
12/12/202339233824
12/13/20233443061082
12/13/202339233824
12/14/20233443061082
12/14/202339233824
12/15/20233443061082
12/15/202339233821
12/16/20233443061082
12/16/202339233821
12/17/20233443061082
12/17/202339233821
12/18/20233443061082
12/18/202339233821
12/19/20233443061082
12/19/202339233821
12/20/20233443061082
12/20/202339233821
12/21/20233443061082
12/22/20233443061042
12/23/20233443061042
12/24/20233443061022
12/25/20233443061022
12/26/20233443061022
12/27/20233443061002
12/28/20233443061002
12/29/20233443061110
12/30/20233443061206
12/31/20233443061206
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how the semantic model looks like, but please try something like below whether it suits your requirement.

 

Current DAX for Inventory: =
VAR MaxPeriodID =
    MAX ( 'Date'[date_key] )
RETURN
    CALCULATE (
        SUM ( Inventory[BATCH_WEIGHT_TONS] ),
        'Date'[date_key] = MaxPeriodID
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Hi @Jihwan_Kim ,

 

I added '+ 0' to your DAX suggestion and that solved the issue in Dec 2023, but in Jan 2023 now it now shows zero for the total because not finished with the month and it's returning the value on the max day of the period. How can it return the max date key from yesterday since the inventory snapshots are from the prior day. 

 

Current DAX for Inventory Tons2: =
VAR MaxPeriodID =
    MAX ( 'Date'[date_key] )
RETURN
    CALCULATE (
        SUM ( Inventory[BATCH_WEIGHT_TONS] ) + 0,
        'Date'[date_key] = MaxPeriodID
    )

 

JKarrick_0-1705702458481.pngJKarrick_1-1705702506310.png

 

Thanks in advance for your help!

I've been out of the office a while but still have my issue so following up to see if any other suggestions @v-yaningy-msft @Jihwan_Kim 

 

The DAX calculation suggested returns the correct value for history, but since it uses the MAX of the Date Key it returns zero for the current month. The Feb 2024 total shows zero, but when expanded to the day level, there are 25 tons on 2/1/2024 so the Feb total should be 25. I would like it to use the current date - 1 day since inventory snapshots are one day behind.  

 

JKarrick_0-1706911327157.png

 

JKarrick_1-1706911631153.png

 

Thanks in advance for your help!

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.