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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Sandritto
Frequent Visitor

Calculating stock day over day

Hi everyone,

 

I was trying to move my Order Schedule on to Power BI. I already have my querys from the database onto Power BI, but can´t figure out the correct measures.

 

This screenshot is what I use at the moment. Simple outdated excel made manually and few formulas.

 

Screen.PNG

 

As you can see formulas in Excel are:

 

  • Final Stock = Initial Stock + Offer - Demand
  • Initial Stock = Previous Day Initial Stock

 

Trouble comes transforming this formulas in to Power BI measures.

 

Any advice?

 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Sandritto ,

Try this:

1. Create a column, which is the first value of "Initial Stock".

Column = 23.5

2. Create columns.

Measure 1 = MAX ( Table2[Offer] ) - MAX ( Table2[Demand] )
Measure 2 =
SUMX (
    FILTER ( ALLSELECTED ( Table2 ), Table2[Date] <= MAX ( Table2[Date] ) - 1 ),
    [Measure 1]
)
Initial Stock = MAX([Column])+[Measure 2]
Final Stock =
VAR m =
    SUMX (
        FILTER ( ALLSELECTED ( Table2 ), Table2[Date] <= MAX ( Table2[Date] ) ),
        [Measure 1]
    )
RETURN
    m + MAX ( [Column] )

demand.PNG

 

PBIX file attached.

 

Best Regards,

Icey

 

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

View solution in original post

2 REPLIES 2
Icey
Community Support
Community Support

Hi @Sandritto ,

Try this:

1. Create a column, which is the first value of "Initial Stock".

Column = 23.5

2. Create columns.

Measure 1 = MAX ( Table2[Offer] ) - MAX ( Table2[Demand] )
Measure 2 =
SUMX (
    FILTER ( ALLSELECTED ( Table2 ), Table2[Date] <= MAX ( Table2[Date] ) - 1 ),
    [Measure 1]
)
Initial Stock = MAX([Column])+[Measure 2]
Final Stock =
VAR m =
    SUMX (
        FILTER ( ALLSELECTED ( Table2 ), Table2[Date] <= MAX ( Table2[Date] ) ),
        [Measure 1]
    )
RETURN
    m + MAX ( [Column] )

demand.PNG

 

PBIX file attached.

 

Best Regards,

Icey

 

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

Can I get the PBI file of this solution?

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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