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
Anonymous
Not applicable

Calculating current inventory for a particular date

I have a warehouse transaction table having columns such as date_of_transaction and quantity bought or sold. The positive value of quantity means the product was bought and negative value means the product was sold.

DateQuantity
24 July 20194000
26 July 20196000
30 July 2019-2000
4 August 2019-1000
6 August 201910000

I want to create another table from this table that will give me the current stock in the warehouse(all products combined) on a certain date. The output table should have all the dates in a serially order. The table should look like this:

DateStock Available(Current Inventory)
24 July 20194000
25 July 20194000
26 July 201910000
27 July 201910000
28 July 201910000
29 July 201910000
30 July 20198000
31 July 20198000
1 August 20198000
2 August 20198000
3 August 20198000
4 August 20197000
5 August 20197000
6 August 201917000

The dates on which the transaction didnt occur should also be there in the output table. How should I do it?

2 ACCEPTED SOLUTIONS
dedelman_clng
Community Champion
Community Champion

Hi @Anonymous -

 

If you want it as a table in your model, do the following

 

1) Create a date table (CALENDARAUTO() usually works well). Mark this new table as a Date table and give it a relationship to your data table (it will probably be 1-to-1, but that's fine for what we're doing).

 

2) Create a new calculated table

InvHistory =
ADDCOLUMNS (
    DateTab,
    "Stock Available", TOTALYTD ( SUM ( Inventory[Quantity] ), DateTab[Date] )
)

2020-08-11 12_28_01-N_and_BASE_problem (3) - Power BI Desktop.png

 

Hope this helps

David

View solution in original post

Hi @Anonymous  - 

 

The general pattern for a cumulative total that does not reset each year is

 

Stock Available =
CALCULATE (
    SUM ( Inventory[Quantity] ),
    FILTER ( ALL ( DateTab ), DateTab[Date] <= MAX ( DateTab[Date] ) )
)

 

Hope this helps

David

View solution in original post

5 REPLIES 5
dedelman_clng
Community Champion
Community Champion

Hi @Anonymous -

 

If you want it as a table in your model, do the following

 

1) Create a date table (CALENDARAUTO() usually works well). Mark this new table as a Date table and give it a relationship to your data table (it will probably be 1-to-1, but that's fine for what we're doing).

 

2) Create a new calculated table

InvHistory =
ADDCOLUMNS (
    DateTab,
    "Stock Available", TOTALYTD ( SUM ( Inventory[Quantity] ), DateTab[Date] )
)

2020-08-11 12_28_01-N_and_BASE_problem (3) - Power BI Desktop.png

 

Hope this helps

David

Anonymous
Not applicable

Hi. Your solution definitely did the trick for me thanks.

I just wanted to know what changes would I have to make in order to use this formula for multi-year scenario. I have data ranging right from 2017 to 2020.

Because it is only calculating for a single year.

Thanks

 

Hi @Anonymous  - 

 

The general pattern for a cumulative total that does not reset each year is

 

Stock Available =
CALCULATE (
    SUM ( Inventory[Quantity] ),
    FILTER ( ALL ( DateTab ), DateTab[Date] <= MAX ( DateTab[Date] ) )
)

 

Hope this helps

David

Anonymous
Not applicable

Thanks. That worked!

amitchandak
Super User
Super User

@Anonymous , Join with date table and try this measure

Stock Available(Current Inventory = CALCULATE(lastnonblankvalue(Table[Date], MAX(Table[Quantity]),filter(date,date[date] <=maxx(date,date[date])))

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.