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

btreg

New Member
Joined
Feb 29, 2016
Messages
26
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
 

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,138
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))))
 

btreg

New Member
Joined
Feb 29, 2016
Messages
26
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
 

sheetspread

Well-known Member
Joined
Sep 19, 2005
Messages
5,112
=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])))
 

btreg

New Member
Joined
Feb 29, 2016
Messages
26
Hi sheetspread - your first solution worked perfectly, thank you!
 

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,138
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))}
 

Forum statistics

Threads
1,082,117
Messages
5,363,256
Members
400,723
Latest member
Jsdk

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top