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
hammerman
Frequent Visitor

Opening Stock For Multiple Products

Hi Power BIers,

I've got a stock adjustment table that I'd like to use to calculate opening stock level. It's across multiple products and dates. 

 

I'd essentially like to fill down the opening balance by date until a new opening balance is entered. But then I'd also like to sum across products. Here's what I'm after. 

 

Fill Down and Sum Across.png

 

Here's my data table in Excel: 

data table in excel.png

 

And here's what I'd like the output to look like in Power BI: 

Final result.png

 

Note that I have a date table and a product control table. The formula needs to use these 2 tables to calculate the final result through this table, the stock adjustment table. 

 

I hope that makes sense. Thanks for your help!

 

 

1 ACCEPTED SOLUTION

Hi, @hammerman 

 

You can manually modify the value of total. Use SELECTEDVALUE ( table[column]1 ) = BLANK ().

Like this:

measure =
IF (
    SELECTEDVALUE ( Date[Date] ) = BLANK (),
    CALCULATE ( SUM ( Table[Inventory Value] ) ),//calculate total sum
    CALCULATE (
        LASTNONBLANKVALUE ( Date[Date], SUM ( Table[Inventory Value] ) ),
        FILTER ( ALL ( 'Date' ), 'Date'[Date] <= MAX ( 'Date'[Date] ) )
    )
)

Did I answer your question? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

Best Regards,
Community Support Team _ Janey

View solution in original post

3 REPLIES 3
hammerman
Frequent Visitor

Thanks @amitchandak although unfortunately that hasn't worked. I'd like it to sum up the total across each product for each date from the inventory table at the total level. This formula just gives me the last non blank.

 

I've got a date table and a product control table in my model. I'm thinking it might be something like for each date SUMX the last non blank?  

 

Screenshot 2022-02-01 072307.png

Hi, @hammerman 

 

You can manually modify the value of total. Use SELECTEDVALUE ( table[column]1 ) = BLANK ().

Like this:

measure =
IF (
    SELECTEDVALUE ( Date[Date] ) = BLANK (),
    CALCULATE ( SUM ( Table[Inventory Value] ) ),//calculate total sum
    CALCULATE (
        LASTNONBLANKVALUE ( Date[Date], SUM ( Table[Inventory Value] ) ),
        FILTER ( ALL ( 'Date' ), 'Date'[Date] <= MAX ( 'Date'[Date] ) )
    )
)

Did I answer your question? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

Best Regards,
Community Support Team _ Janey

amitchandak
Super User
Super User

@hammerman , Prefer to use a Date table, this will ensure all works onlt for date

 

calculate(lastnonblankvalue(Date[Date], Sum(Table[Inventory Value])), filter(all('Date'), 'Date'[Date] <= max( 'Date'[Date] )))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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!

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.