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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Quite_lost
Frequent Visitor

Measure returning unexpected value

Hi, I quite new to PowerBI and DAX structure and need some help.

I am trying to make an Inventory History dashboard that has a measure Average Sales by month in the context of shortage of stock of the product. The period when there is a shortage of "Product A" must not be considered in the average, thus "Average SAles by Month "in stock".

 

The problem is: the expected result differs from what is shown. For an example, in the period between 01/10/2019 to 30/09/2020 (dd/mm/yyyy) the expect average would be 18930, not 17633.

 

inventory history 01.jpg

 

Also, how do I upload the dummy file in here?

 

Any help will be much appreciated.

 

Best wishes.

1 ACCEPTED SOLUTION

Hi @Quite_lost ,

 

Based on your description, I checked your example pbix and found the problem.

The reason is that you turn off the interaction between Movement Type slicer and Days "in stock".

Correspondingly, you need to clear the filter of Movement Type in the calculation.

Average Sales by Month "in stock" = var t = [Total Quantity]
var m = CALCULATE([Months "in stock"],ALL('Stock History'[Movement Type]))
return DIVIDE(t,m)

Measure returning unexpected value.PNG

 

Best Regards,
Liang
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

4 REPLIES 4
amitchandak
Super User
Super User

@Quite_lost , can you share formulas of three involved

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Here is the pbix file.

 

Here are the formulas I'm using:

 

#Total Quantity = SUM('Stock History'[Quantity]) *-1

#Cumulative Total = CALCULATE( [Total Quantity], FILTER( ALL( Dates[Date] ), Dates[Date] <= MAX( Dates[Date] ) ) )

#Days "in stock" = COUNTROWS(FILTER(ADDCOLUMNS(CROSSJOIN( VALUES( Dates[Date] ), VALUES('Stock History'[Product]) ), "Inventory Levels", [Cumulative Total] ), [Inventory Levels] <> 0 && NOT( ISBLANK( [Inventory Levels] ) ) ) )-1

#Days "zero stock" = COUNTROWS( FILTER( ADDCOLUMNS( CROSSJOIN( VALUES( Dates[Date] ), VALUES('Stock History'[Product]) ), "Inventory Levels", [Cumulative Total] ), [Inventory Levels] = 0 && NOT( ISBLANK( [Inventory Levels] ) ) )

#Months "in stock" = [Days "in stock"] / 30.41666

#Average Sales by Month "in stock" = [Total Quantity] / [Months "in stock"]

 

 

Hi @Quite_lost ,

 

Based on your description, I checked your example pbix and found the problem.

The reason is that you turn off the interaction between Movement Type slicer and Days "in stock".

Correspondingly, you need to clear the filter of Movement Type in the calculation.

Average Sales by Month "in stock" = var t = [Total Quantity]
var m = CALCULATE([Months "in stock"],ALL('Stock History'[Movement Type]))
return DIVIDE(t,m)

Measure returning unexpected value.PNG

 

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

Wow, that really worked!

Thank you very much!

I need to learn a lot more about filter and contexts.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.