3

I have a data table which, among other things, contains a list of Values, each is assigned a Group ID.

I would like to sum the max value of each group.

I can do this easily by using a helper table (with MAXIFS) as can be seen below. However, for various reasons, I would like to avoid any helper columns/tables and produce the result from a single, non-CSE, formula.

enter image description here

How can this be done?

8
  • 2
    Not using array formulas would be tricky I think. A challenge for Scott...
    – SJR
    Dec 12, 2019 at 13:52
  • 2
    Outside of dynamic array formula, like below, there is no way without CSE or vba. Dec 12, 2019 at 14:02
  • 1
    @ScottCraner Not even a SUMPRODUCT solution? I thought all array formulas could be reformatted into a SUMPRODUCT? So far, I have =SUMPRODUCT($B$3:$B$14*(B3:B14=MAXIFS(B3:B14,A3:A14,A3:A14))) but my problem is removing the duplicate max values e.g. group 2 in my example. I am currently trying to sum them and divide by the count... but i'm having difficulty.
    – Gravitate
    Dec 12, 2019 at 14:07
  • 2
    @ScottCraner please see my answer. It seems to work (even with text as the group ID) but I haven't fully tested it yet. Can you see any obvious problems/improvements that I may have missed?
    – Gravitate
    Dec 12, 2019 at 14:22
  • 4
    Appears I was wrong, I am blaming it on the fact that I am just waking, yeah thats it, not enough caffeine. Good job. Dec 12, 2019 at 14:27

4 Answers 4

7

Dynamic Array Functions

IF you have access to the new dynamic array functions, @MichaelWycisk has a much simpler solution (https://stackoverflow.com/a/59306217/1473412)

Sadly I do not.


SUMPRODUCT

I have managed to do it using SUMPRODUCT:

=SUMPRODUCT(
    (
        $B$3:$B$14
        *
        ($B$3:$B$14=MAXIFS($B$3:$B$14,$A$3:$A$14,$A$3:$A$14))
    )
    /
    COUNTIFS($B$3:$B$14,MAXIFS($B$3:$B$14,$A$3:$A$14,$A$3:$A$14),$A$3:$A$14,$A$3:$A$14)
)

enter image description here

The way it works is to multiply the values by whether or not it is the max value for the group.
Then it divides that by the count of values which are the max value for the group.

1
  • 2
    I should have thought of that, not had my morning caffeine yet. Dec 12, 2019 at 14:23
5
+100

You could also try this:

= SUMPRODUCT( 
 MAXIFS( $B$2:$B$14, $A$2:$A$14, $A$2:$A$14 )
 / COUNTIFS( $A$2:$A$14, $A$2:$A$14 ) )

Explanation: (provided now as previously I was travelling).

MAXIFS: Returns the MAX value for each Group.
COUNTIFS: Returns the count of each Group.
SUMPRODUCT: Returns the addition of the division of each Group's Max value by it's Count.

enter image description here

0
4

I understand you do not want to have array formulas. But if you would be fine with the new dynamic arrays (no CONTROL + SHIFT + ENTER needed), you might use this formula:

=SUM(MAXIFS(B3:B14,A3:A14,UNIQUE(A3:A14)))

Of course, this will only work if the UNIQUE function is already available to you.

5
  • 1
    Thanks... turns out they aren't available to me but i'm not sure why not. Should they be available in the latest version of 365? Or are they "Office Insiders" only still?
    – Gravitate
    Dec 12, 2019 at 14:04
  • 1
    @Gravitate No, I am not an Office Insider and I have them on two machines. I was recently told here on SO that it depends on your update circle. Sorry if the solution does not work for you. Dec 12, 2019 at 14:06
  • No problem. Thank you for your help. That will certainly make things easier when I do get the update :)
    – Gravitate
    Dec 12, 2019 at 14:09
  • @Gravitate, go to your account page in Excel. It will tell you the schedule of updates. Dec 12, 2019 at 14:30
  • 1
    @ScottCraner Thanks, but unfortunately it's not just my updates I have to worry about. The sheet is to be used by a number of people... many of whom are months behind with updates.
    – Gravitate
    Dec 12, 2019 at 14:39
1

Try this:

=SUM(MAXIFS(B3:B14,A3:A14,{1,2,3,4}))

enter image description here

3
  • 1
    Thanks but that would require me to know all the group names in advance.
    – Gravitate
    Dec 22, 2019 at 8:57
  • With the new unique function that returns an array of unique values it can be done without knowing in advance the values: =SUM(MAXIFS(B3:B14,A3:A14,UNIQUE(A3:A14)))
    – cte6
    Mar 23, 2020 at 13:54
  • Yes... if you check above, that was @MichaelWycisk's answer, which he posted 10 days before you posted yours: stackoverflow.com/a/59306217/1473412
    – Gravitate
    Mar 23, 2020 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.