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
NBOnecall
Helper V
Helper V

Measure total is not correct

Hi,

 

Need some help and yes I know there are a dozen of threads for this same exact issue, but whatever I am doing in relation to those answers isn't working for me.

 

My measure is the following:

Lost Sales = sum('ns vwInventorySnapshot'[OutofStock])*AVERAGE('ns SalesRegister'[Sales/Unit])*AVERAGE('ns SalesRegister'[SalePerDay])

 

I have items that can be in two different locations that are in the visual. Here is the visual.

 

Annotation 2020-02-05 114041.png

Hopefully you all can help me figure out what formula is needed to get a correct Lost Sales total.

 

Thank you,

Noel

 

16 REPLIES 16
masonlee01
Regular Visitor

Assuming 'ns vwInventorySnapshot' and 'ns SalesRegister' are two tables joined by InternalID, try this

 

 

avgSalesPerUnit = AVERAGEX('ns SalesRegister', 'ns SalesRegister'[Sales/Unit])
Lost Sales = CALCULATE(SUM('ns vwInventorySnapshot'[OutofStock]) * [avgSalesPerUnit])

 

 

If that doesn't work try

 

 

avgSalesPerUnit = AVERAGEX('ns SalesRegister', 'ns SalesRegister'[Sales/Unit])
Lost Sales = CALCULATE(SUM('ns vwInventorySnapshot'[OutofStock]) * [avgSalesPerUnit], ALL('ns SalesRegister'))

 

 

ALL might need to be ALLSELECTED or KEEPFILTERS - I'm not great with those.

This doesn't get me the numbers we need. Actually using the Lost Sales mesaure it doesn't even multiple the OutofStock correctly, it just looks like the OutOfStock is just assuming 1 it looks like. The output of avgSalesPerUnit equals Lost Sales measure.

 

Thanks,

Noel

Is the pricing averaging out correctly across the units in mult locations?  Is there a relationship defined between those tables?

The avgSalesPerUnit matches my Average of Sales/unit columns.

 

SalesRegister and InventorySnapshot is linked via internal ID of NetsuiteItem table.

Without having the data, hard to play with.  Maybe this will work?

 

lostSales = SUMX(SUMMARIZE('ns SalesRegister', 'ns SalesRegister'[InternalId], "myAvg", AVERAGE('ns SalesRegister'[Sales/Unit])), [myAvg] * 'ns vwInventorySnapshot'[OutofStock])

 

I'm getting an error with the ns vwInventorySnapshot'[OutofStock] piece. Looks like it is not an available option for the SUMX formula.

 

Alright, i got it with some dummy data.

 

invID       itemID       OOS         Price

aa1225
ba1246
ca1367
da1318
ea1409
fa14410
ga15211
ha16412

 

 

avgPrice=AVERAGEX(data, data[Price])
blendedPrice=CALCULATE([avgPrice], ALLEXCEPT(data, data[itemID]))
totalOOS=SUMX(data, data[OOS])
lostSales=[totalOOS]*[blendedPrice]

 

 

So all these equations work out, but again I think I am in the same boat as before. The total lines for the Lost Sales does not sum correctly. From my understanding I have to use a filter equation to sum the rows that are on my visual.

 

Thank you for you help so far.

 

What is it summing too? The average of all prices times the sum of all out of stock instead of the individual lost sales?

Here is the visualization when filtered down to just 1 item in 2 different locations.

 

Measure Not Summing.png

 

As you can see the "Lost SalesTest" column does not sum correctly. Here are my forumulas.

 

Lost SalesTest = [totalOOS]*[blendedPrice]*[avgSalesPerDay]
totaloos = sumx('ns vwInventorySnapshot', 'ns vwInventorySnapshot'[OutofStock])
blendedprice = CALCULATE([avgSalesPerUniTest],ALLEXCEPT('ns NetsuiteItem','ns NetsuiteItem'[InternalId]))
avgSalesPerDay = AVERAGEX('ns SalesRegister', 'ns SalesRegister'[SalePerDay])

So I am at a lost of what Forumula I need on the measure to get the total line to SUM the measure instead of performing the Measure on the total line. I feel like I have tried countless other suggestions found throughout the forum, but still end up not getting the correct sum on the total line.

I created a powerBI report with a few example measures that seem to work and add things up correctly.

 

Here

 

I think the simplest is:

 

blendedPrice = CALCULATE([avgPrice], ALLEXCEPT(data, data[itemID]))
lostSales = sumx(data, [totalOOS]*[blendedPrice])

 

But I have an example that uses summarize, addcolumns & allselected.  Maybe it's a bit more robust.

blendedPrice3 = AVERAGEX(ADDCOLUMNS(SUMMARIZE(data, data[itemID]), "bp3", CALCULATE(AVERAGEX(ALLSELECTED(data), data[Price]))), [bp3])

 

 

Thank you for your help! It now sums correctly, but only if one of my locations are selected.

 

Here are the formulas I am using:

 

lostSalesExample = sumx('ns NetsuiteItem',[totaloos]*[blendedAvgSale]*[avgSalesPerDay])
avgSalesPerDay = AVERAGEX('ns SalesRegister', 'ns SalesRegister'[SalePerDay])
blendedAvgSale = CALCULATE([AvgSale],ALLEXCEPT('ns NetsuiteItem','ns NetsuiteItem'[InternalId]))
totaloos = sumx('ns vwInventorySnapshot', 'ns vwInventorySnapshot'[OutofStock])

 

The NetSuiteItem table does not have the locations, it is another table called Locations.

 

Thank you again.

 

 

The Lost Sales sum to a little of 16k when exporting the data to Excel, but it is showing about 51k on the total line in Power BI. 

 

I’m not at office, but probably needs to be an iterator or calculate statement in the lost sales. Try wrapping it with calculate or sumx instead of just adding the measures together. You want to force it to go row by row multiplying then adding, not taking the grand totals and multiplying.

rolling_total.png

 

You'll need to adjust to your tables & columns, but I think it's working

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.