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