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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

Rolling Stock Position With Gaps In Months

Hi

 

I've loaded Item Ledger Entries table from Business Central into Power BI.

I'd like to see my rolling stock position by month, my issue is that if there's a month with no stock change / no data, it will show as 0 when it should take the last available data point e.g. if as of February there was £1.3m of stock value and no data in March then show £1.3m.

 

I'm currently using the below measure:

 

Cumulative Inventory Value =
    CALCULATE(
        SUM('Item Ledger Entries'[costAmountActual]),
            FILTER(
                ALL('Item Ledger Entries'),
                    'Item Ledger Entries'[postingDate] <= MAX('Item Ledger Entries'[postingDate]
            )
        )
    )
 
Lewis_S_William_0-1719318076219.png

 

 

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@Anonymous,

 

This can be solved with a date table. There are various ways to create a date table--here's a DAX calculated table:

 

Date = 
ADDCOLUMNS (
    CALENDARAUTO (),
    "Month Start Date", DATE ( YEAR ( [Date] ), MONTH ( [Date] ), 1 )
)

 

Create a 1:* relationship between the date table and data (fact) table:

 

DataInsights_0-1719583035644.png

 

Create measures:

 

Sum of Stock Value = SUM ( 'Table'[Stock Value] )
Running Total = 
CALCULATE ( [Sum of Stock Value], FILTER ( ALLSELECTED ( 'Date' ), 'Date'[Date] <= MAX ( 'Date'[Date] ) ) )

 

Result:

 

DataInsights_1-1719583122601.png

 

Whenever possible, use dimension table fields in visuals (e.g., 'Date'[Month Start Date]).





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

Proud to be a Super User!




View solution in original post

8 REPLIES 8
DataInsights
Super User
Super User

@Anonymous,

 

This can be solved with a date table. There are various ways to create a date table--here's a DAX calculated table:

 

Date = 
ADDCOLUMNS (
    CALENDARAUTO (),
    "Month Start Date", DATE ( YEAR ( [Date] ), MONTH ( [Date] ), 1 )
)

 

Create a 1:* relationship between the date table and data (fact) table:

 

DataInsights_0-1719583035644.png

 

Create measures:

 

Sum of Stock Value = SUM ( 'Table'[Stock Value] )
Running Total = 
CALCULATE ( [Sum of Stock Value], FILTER ( ALLSELECTED ( 'Date' ), 'Date'[Date] <= MAX ( 'Date'[Date] ) ) )

 

Result:

 

DataInsights_1-1719583122601.png

 

Whenever possible, use dimension table fields in visuals (e.g., 'Date'[Month Start Date]).





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

Proud to be a Super User!




Anonymous
Not applicable

Hi @Anonymous ,

I create a table as you mentioned.

vyilongmsft_0-1719366469804.png

Then I create a measure and here is the DAX code.

Measure = 
VAR _Value =
    SUMX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Date] <= MAX ( 'Table'[Date] )
                && 'Table'[Stock Value] > 0
        ),
        'Table'[Stock Value]
    )
RETURN
    IF ( SUM ( 'Table'[Stock Value] ) <> 0, SUM ( 'Table'[Stock Value] ), _Value )

vyilongmsft_1-1719366734094.png

 

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Appreciate the help. Unfortunately isn't the solution.

 

Below is what I should expect to see.

 

Lewis_S_William_0-1719390703833.png

Lewis_S_William_1-1719390780207.png

 

The issue is if there's absolutely no data for a specific month such as below (missing May) then it should take the previous months total

 

Lewis_S_William_2-1719391617390.png

 

 

Anonymous
Not applicable

Hi @Anonymous ,

I changed my DAX code.

Measure = 
VAR _currentdate =
    MAX ( 'Table'[Date] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Stock Value] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Date] <= _currentdate )
    )

Then I get what you want.

vyilongmsft_0-1719469056865.png

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Close but doesn't address if the table is missing data.

 

Let's say I've created a date table for 01/01 - 31/12 and connected it to the stock table. If I drag in the date table date column, the measure would be blank for 02/01, 03/01 etc.. when actually the stock position as of 03/01 would still be 10 not blank.

 

Lewis_S_William_0-1719476621028.png

 

Edited with clearer expected results

 

Lewis_S_William_1-1719478034956.png

 

 

Anonymous
Not applicable

Hi @Anonymous ,

I'm sorry that Power BI doesn't have such a smart feature at the moment, and the requirement that you mentioned that an undisplayed date still needs to be returned to the previous value can't be realized yet.

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

No problem, thank you so much for your help

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

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.