Question

I am looking to find the mode (most occurrent) value of one column, given another column.

I know how to do it but the calculation takes multiple minutes and can make Excel unresponsive. Therefore I am looking for a better way.


Suppose my data looks like this

group | Level
1       D
1       A
1.1     B
1       C
1       A
1       E

Then I want the output to look like this:

group | LevelMode
1       A
1.1     B

Assuming the data is in the upper left corner of the worksheet, I am now using this formula, which I drag along the C column:

=COUNTIFS(A:A;A2;B:B;B2)/COUNTIF(A:A;A2)

This gives me the ratio of values within the group. Afterwards I remove all that are not above 0.5 as well as duplicates, giving me the mode for each group if it exists.

This formula does exactly what I want, but for about 50000 lines it simply takes too many resources. I expected to find this in the pivot table options, or after a quick search online, but I have not found any way to achieve my goal.

I have decent hardware, a fairly recent version of Excel and would prefer to do this without macro's. However, if macros are required to achieve this then so be it.

Was it helpful?

Solution

Try this:

Step 1.

Create the Pivot Table and place in RowLabels "Group" and under it "Level". Now, place "Level" as count in "Values" field.

Step 2.

See the picture below. Click in the black arrow in the right side of "Level" (you can't see it in the picture but it is supposed to be inside the red circle). Choose "Values Filters", then "Top 10" and then set the number to 1 (top 1). Done!!

Attention: you need to do step 2 for "Level". If you do the same to "Group" it will not work.

enter image description here

Edit: this is the result and how the Pivot Table should look like.

enter image description here

Now to shape the output to the desired format:

  1. Under PivotTable tools > Design, set the Report Layout to Tabular form
  2. Disable totals and subtotals

Assuming default settings you can now easily copy the list of Groups and LevelModes

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top