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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

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 @Anonymous

 

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 @Anonymous

 

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!  

Anonymous
Not applicable

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 @Anonymous

 

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!  

Anonymous
Not applicable

@LivioLanzo,

 

great thank you! 

Hello @Anonymous

 

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
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.