Skip to main content
cancel
Showing results for 
Search instead 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.

Reply
Norbertus
Helper V
Helper V

inventory last snapshot not all days

Hi,

 

we have the next problem.

 

Several times a year, not every day or month, we count the products in a warehouse.

This inventory table is connected to a date calendar.

 

Now we i want to know for each day, month, quarter of a year what the count of the products is.

But if we don't have a inventory in example March we need the last value before.

 

I tried a lot of examples, but the most asume that there is a frequent inventory. In our situation we get a "zero" and we need the last value

1 ACCEPTED SOLUTION

Hello @Norbertus

 

I am assuming you already have such model in place:

 

Capture.PNG

 

I have added a calculated column in the Calendar Table with this formula:

 

HasInventoryEntry = 
NOT( ISEMPTY( RELATEDTABLE( Inventory ) ) )

And then used this measure in the Matrix:

 

Quantity Balance  = 
VAR mxDte = MAX( 'Calendar'[Date] )
RETURN
CALCULATE(
    SUM( Inventory[Quantity] ),
    CALCULATETABLE(
        LASTDATE( 'Calendar'[Date] ),
        'Calendar'[HasInventoryEntry] = TRUE(),
        'Calendar'[Date] <= mxDte
    )
)

Capture.PNG

 

 

If the inventory can have different categories, like for instance North and South, then you can do it like this:

 

Capture.PNG

 

Capture.PNG

 

Quantity Balance = 
VAR mxDte =
    MAX ( 'Calendar'[Date] )
RETURN
SUMX(
    VALUES( Regions[Region] ),
        CALCULATE (
            SUM ( Inventory[Quantity] ),
            LASTNONBLANK (
                CALCULATETABLE (
                    VALUES ( 'Calendar'[Date] ),
                    'Calendar'[HasInventoryEntry] = TRUE (),
                    'Calendar'[Date] <= mxDte
                ),
                CALCULATE ( COUNTROWS ( Inventory ) )
            )
        )
)

Capture.PNG

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

View solution in original post

5 REPLIES 5
LivioLanzo
Solution Sage
Solution Sage

Hi @Norbertus

 

are you able to post a data sample?

 

 

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Inventory dateQuantity
1-1-2018500
15-1-2018550
1-6-2018400
1-8-2018300

 

This should be the result

 

PeriodIn stock
januari550
februari550
maart550
april550
mei550
juni400
juli400
augustus300
september300
oktober300
november300
december 

Hello @Norbertus

 

I am assuming you already have such model in place:

 

Capture.PNG

 

I have added a calculated column in the Calendar Table with this formula:

 

HasInventoryEntry = 
NOT( ISEMPTY( RELATEDTABLE( Inventory ) ) )

And then used this measure in the Matrix:

 

Quantity Balance  = 
VAR mxDte = MAX( 'Calendar'[Date] )
RETURN
CALCULATE(
    SUM( Inventory[Quantity] ),
    CALCULATETABLE(
        LASTDATE( 'Calendar'[Date] ),
        'Calendar'[HasInventoryEntry] = TRUE(),
        'Calendar'[Date] <= mxDte
    )
)

Capture.PNG

 

 

If the inventory can have different categories, like for instance North and South, then you can do it like this:

 

Capture.PNG

 

Capture.PNG

 

Quantity Balance = 
VAR mxDte =
    MAX ( 'Calendar'[Date] )
RETURN
SUMX(
    VALUES( Regions[Region] ),
        CALCULATE (
            SUM ( Inventory[Quantity] ),
            LASTNONBLANK (
                CALCULATETABLE (
                    VALUES ( 'Calendar'[Date] ),
                    'Calendar'[HasInventoryEntry] = TRUE (),
                    'Calendar'[Date] <= mxDte
                ),
                CALCULATE ( COUNTROWS ( Inventory ) )
            )
        )
)

Capture.PNG

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

@LivioLanzo,

 

great thank you! 

Hello @Norbertus

 

I am assuming you already have such model in place:

 

Capture.PNG

 

I have added a calculated column in the Calendar Table with this formula:

 

HasInventoryEntry = 
NOT( ISEMPTY( RELATEDTABLE( Inventory ) ) )

And then used this measure in the Matrix:

 

Quantity Balance  = 
VAR mxDte = MAX( 'Calendar'[Date] )
RETURN
CALCULATE(
    SUM( Inventory[Quantity] ),
    CALCULATETABLE(
        LASTDATE( 'Calendar'[Date] ),
        'Calendar'[HasInventoryEntry] = TRUE(),
        'Calendar'[Date] <= mxDte
    )
)

Capture.PNG

 

 

If the inventory can have different categories, like for instance North and South, then you can do it like this:

 

Capture.PNG

 

Capture.PNG

 

Quantity Balance = 
VAR mxDte =
    MAX ( 'Calendar'[Date] )
RETURN
SUMX(
    VALUES( Regions[Region] ),
        CALCULATE (
            SUM ( Inventory[Quantity] ),
            LASTNONBLANK (
                CALCULATETABLE (
                    VALUES ( 'Calendar'[Date] ),
                    'Calendar'[HasInventoryEntry] = TRUE (),
                    'Calendar'[Date] <= mxDte
                ),
                CALCULATE ( COUNTROWS ( Inventory ) )
            )
        )
)

Capture.PNG

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Helpful resources

Announcements
Microsoft Fabric Learn Together

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

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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