Return count of unique records in one field, based on sum of another field

btreg

New Member
Joined
Feb 29, 2016
Messages
30
To illustrate the question I have created some dummy data below:

CountryProductSales Volume
FranceShoes10
France
Shoes20
FranceShoes30
FranceBoots5
FranceBoots5
FranceHat10
FranceHat5

<tbody>
</tbody>

I want to create a measure that will return the number of products with a total sales volume of less than 20 (i.e. the result would be "2" from the above data, as "Boots" and "Hats" have sales volumes of 10 and 15 respectively.

Any help with creating the measure would be much appreciated. Thanks in advance!

Ben
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
CountryProductSales VolumeSubtotal20
FranceShoes10602
FranceShoes2060Boots
FranceShoes3060Hat
FranceBoots510
FranceBoots510
FranceHat1015
FranceHat515

<tbody>
</tbody>

In D2 just enter and copy down:

=SUMIFS($C$2:$C$8,$B$2:$B$8,$B2)

In E2 control+shift+enter, not just enter:

=SUM(IF(FREQUENCY(IF(1-($B$2:$B$8=""),IF($D$2:$D$8>0,IF($D$2:$D$8<E1,MATCH($B$2:$B$8,$B$2:$B$8,0)))),ROW($B$2:$B$8)-ROW($B$2)+1),1))

In E3 control+shift+enter, not just enter, and copy down:

=IF(ROWS($E$3:E3)>$E$2,"",INDEX($B$2:$B$8,SMALL(IF(FREQUENCY(IF(1-($B$2:$B$8=""),IF($D$2:$D$8>0,IF($D$2:$D$8<$E$1,MATCH($B$2:$B$8,$B$2:$B$8,0)))),ROW($B$2:$B$8)-ROW($B$2)+1),ROW($B$2:$B$8)-ROW($B$2)+1),ROWS($E$3:E3))))
 
Upvote 0
Hi Aladin,

Thank you for the reply, but I need to create this in the form of a DAX measure, so it will work dynamically within a Pivot Table.

Ben
 
Upvote 0
=sumx(values(Table1[Product]),if([Sum of Sales Volume]<20,1,0))

or you could have a calculated field with:

=if(CALCULATE(SUMX(Table1,[Sales Volume]),FILTER(Table1,[Product]=EARLIER([Product])))<20,1,0)/CALCULATE(countX(Table1,[Sales Volume]),FILTER(Table1,[Product]=EARLIER([Product])))
 
Upvote 0
Hi Aladin,

Thank you for the reply, but I need to create this in the form of a DAX measure, so it will work dynamically within a Pivot Table.

Ben

I missed that...

By the way, just for the record, the formula in E2 is:

{=SUM(IF(FREQUENCY(IF(1-($B$2:$B$8=""),IF($D$2:$D$8>0,IF($D$2:$D$8 < E1,MATCH($B$2:$B$8,$B$2:$B$8,0)))),ROW($B$2:$B$8)-ROW($B$2)+1),1))}
 
Upvote 0

Forum statistics

Threads
1,214,575
Messages
6,120,342
Members
448,956
Latest member
Adamsxl

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