Summing a measure if another measure is within a range of a maximum

smiths87

Board Regular
Joined
Aug 7, 2006
Messages
106
I can't seem to wrap my head around this. I have store level data, and 'Stores Scanning' on the right is a distinct count of the stores scanning for each group by period. You can see in 'Group A' that the store didn't really start the full sell off until Period 2, and then the stores selling was roughly the same for 3 & 4.

What I need to do in the Left table is get a sum of the dollars sold only when that 'Stores Scanning' measure is above a certain threshold for the period. So sum dollars if the number of individual stores scanning for the period is, for example, within 10 stores of the maximum for the 'Stores Scanning' measure across all of the periods for that group. (Which is visualized in the table on the right.)

I've tried several iterations using calculate, summarize, etc, and I just can't get anything to work. I just don't understand how to get the max of the measure for each period, and then use that as a filter.

(Just a little more clarification - for Group A I would want the 'Dollar for only full distro' to be the sum of dollars for only periods 2,3,4, since that is where the distribution was at the fullest. And likewise for each group based on their respective maximum of the measure 'Stores Scanning')

Thanks for looking.


Excel 2010
ABCDEFGHIJKLMNO
1GroupDollarsDollars for only full distroStores ScanningPeriod
2A$57,826Group9101112131234
3B$1,103A345455889190
4C$21,503B174759615562727170
5D$278C282929293032343638
6Grand Total$267,627D22324242424242424
Sheet1
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
May need you share out a workbook for me to play with; this LOOKS pretty straight forward. Something like:
CALCULATE([TotalSales], FILTER(Sales, [StoresScanning] > [Threshold])
 
Upvote 0
May need you share out a workbook for me to play with; this LOOKS pretty straight forward. Something like:
CALCULATE([TotalSales], FILTER(Sales, [StoresScanning] > [Threshold])

That is what I thought initially. Famous last words on my part. I started with a formula to sum the dollars only if better than a [Threshold], but I could only do it with a hardcoded value. I couldn't conceptualize how to return the [Threshold] as a variable.

Anyway, spreadsheet attached that has a few notes and the basic tables. Thanks.

Google Docs
 
Upvote 0
Not an easy problem. Or at least, not for me. :) Maybe there is an easier way.... but this is what I think worked. For me.

Code:
// A measure that can find the max scanning stores, across time.
MaxStoresScanning:=MAXX(ALL(POS[Period]), [Stores Scanning])

// Helper measure
Scanning Store Delta From Max := ABS([Stores Scanning] - [MaxStoresScanning])

// Go a period at a time, checking if in this period the stores scanning is close to max... and if so, include the period, else... 0.
FilteredPeriodCount :=SUMX(VALUES(POS[Period]), IF([Scanning Store Delta From Max] < 10, [Total Periods], 0))

// Similiar for dollars
FilteredDollars := SUMX(VALUES(POS[Period]), IF([Scanning Store Delta From Max] < 10, [Dollars], 0))

The tricky part for me was using the IF, instead of some flavor of CALCULATE. It does make some sense, because you are interested in your the comparison at an aggregate level, not row by row, which the calculate would do. The outer SUMX is just trickier to make it work for grand totals, not just 1 period at a time.

Best of luck!
 
Upvote 0
Not really sure I understand what you are trying to do here, but maybe try using =LARGE() within a SUMIF(), where large would be used to calc the threshhold?
 
Upvote 0
Thanks Scottsen! This worked perfectly. Probably take me a while to follow every detail, but I get the broad steps. The If vs. the Calucluate option is very interesting. Can't wait to attempt to wrap my head around that one.
 
Upvote 0
Not really sure I understand what you are trying to do here, but maybe try using =LARGE() within a SUMIF(), where large would be used to calc the threshhold?

I thought about using TOPN in some way, but ScottSen's solution beat me to the punch. Thank god.
 
Upvote 0
TOPN(), CALCULATE and FILTER are not (as far as I know) native excel functions (maybe they are in VBA, my VBA sucks lol)
 
Upvote 0
TOPN(), CALCULATE and FILTER are not (as far as I know) native excel functions (maybe they are in VBA, my VBA sucks lol)


haha, my vba is mildly rusty as well but I'm working on it. Needed this in a powerpivot solution though. Outside of that would have been pretty easy probably (or at least relatively easy). I like the powerpivot way though, jsut need to study up a little more on it.
 
Upvote 0

Forum statistics

Threads
1,223,996
Messages
6,175,869
Members
452,679
Latest member
darryl47nopra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top