Dynamic 365 solution for SUMIF INDEX MATCH

PrettyGood_Not Great

Board Regular
Joined
Nov 24, 2023
Messages
93
Office Version
  1. 365
Platform
  1. Windows
Hi, I am wondering if there is a go to 365 equation that can spill down or possibly even spill in 2d that can replace an old 2016 staple.

SUMIF(Sheet1!Vertical Criteria Range,Vertical Criteria,INDEX(Sheet1!Sum Range,0,XMATCH(Horizontal Criteria,Sheet1!Horizontal Criteria Range,0))

If more information is required I can provide, however I am looking at this as a general case. I use this equation in many different places.

Thank you
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I'm not sure I'd recommend this, but here's one option:

Book1
ABCDEFGHIJKLM
1Vertical CriteriaHorizontal CriteriaOldNewCriteriaABCDEFG
2AlaskaA111111Alaska3418452625446
3OhioC4545Hawaii15425016422210
4HawaiiE6161Alaska117244382648
5AlaskaG167167Ohio49314039434745
6MaineB9090Maine29472718213215
7Maine2543433010331
8Ohio13135372716
9Alaska394774036426
10Alaska27352036333447
11Hawaii611211319255
Sheet13
Cell Formulas
RangeFormula
D2:D6D2=INDEX(SUMIF(F2:F11,UNIQUE(F2:F11),OFFSET(G2:M11,0,SEQUENCE(,COLUMNS(G2:M11),0),,1)),MATCH(A2:A6,UNIQUE(F2:F11),0),MATCH(B2:B6,G1:M1,0))
C2:C6C2=SUMIF($F$2:$F$11,A2,INDEX($G$2:$M$11,0,XMATCH(B2,$G$1:$M$1,0)))
Dynamic array formulas.


It actually calculates every possible combination of criteria and column, then uses the given criteria as an index to that table.
 
Upvote 0
You could use basically the same formula but have it spill down using BYROW

24 01 29.xlsm
ABCDEFGHIJKLM
1Vertical CriteriaHorizontal CriteriaOldNewCriteriaABCDEFG
2AlaskaA111111Alaska3418452625446
3OhioC4545Hawaii15425016422210
4HawaiiE6161Alaska117244382648
5AlaskaG167167Ohio49314039434745
6MaineB9090Maine29472718213215
7Maine2543433010331
8Ohio13135372716
9Alaska394774036426
10Alaska27352036333447
11Hawaii611211319255
Spill SUMIF
Cell Formulas
RangeFormula
D2:D6D2=BYROW(A2:B6,LAMBDA(r,SUMIF(F2:F11,TAKE(r,,1),INDEX(G2:M11,0,XMATCH(TAKE(r,,-1),G1:M1)))))
C2:C6C2=SUMIF($F$2:$F$11,A2,INDEX($G$2:$M$11,0,XMATCH(B2,$G$1:$M$1,0)))
Dynamic array formulas.


You could also spill SUMPRODUCT in a similar way but if the data is very large it may be a bit more sluggish.
Excel Formula:
=BYROW(A2:B6,LAMBDA(r,SUMPRODUCT((F2:F11=TAKE(r,,1))*(G1:M1=TAKE(r,,-1)),G2:M11)))
 
Upvote 0
I like the BYROW suggestion here...I suppose you could also SUM results from some nested FILTER functions to achieve the same, shown in E2:
Book1
ABCDEFGHIJKLM
1Vertical CriteriaHorizontal CriteriaOldNewNew2CriteriaABCDEFG
2AlaskaA111111111Alaska3418452625446
3OhioC454545Hawaii15425016422210
4HawaiiE616161Alaska117244382648
5AlaskaG167167167Ohio49314039434745
6MaineB909090Maine29472718213215
7Maine2543433010331
8Ohio13135372716
9Alaska394774036426
10Alaska27352036333447
11Hawaii611211319255
Sheet3
Cell Formulas
RangeFormula
D2:D6D2=BYROW(A2:B6,LAMBDA(r,SUMIF(F2:F11,TAKE(r,,1),INDEX(G2:M11,0,XMATCH(TAKE(r,,-1),G1:M1)))))
E2:E6E2=BYROW(A2:B6,LAMBDA(r,SUM(FILTER(FILTER(G2:M11,F2:F11=TAKE(r,,1)),G1:M1=TAKE(r,,-1)))))
C2:C6C2=SUMIF($F$2:$F$11,A2,INDEX($G$2:$M$11,0,XMATCH(B2,$G$1:$M$1,0)))
Dynamic array formulas.
 
Last edited:
Upvote 0
I suppose you could also SUM results from some nested FILTER functions to achieve the same,
If the data can be large, I have found sometimes FILTER/FILTER can be a bit slower than SUMIF(S). Also, since this was a general question about method rather than for this specific data, your suggestion might need something more in case the criteria is not met. SUMIF(S) would simply return 0 but your FILTER formula would not.
 
Upvote 0
...your suggestion might need something more in case the criteria is not met. SUMIF(S) would simply return 0 but your FILTER formula would not.
I agree with most of your points, Peter, but doesn't the same issue exist with the SUMIFS solutions?...not the SUMIFS function specifically, but with INDEX/XMATCH used to pass an array to SUMIFS. If XMATCH finds nothing, an error is generated and passed to SUMIFS, which in turn throws an #N/A error. It seems that any of these solutions might need additional work to address a no-match scenario?
 
Upvote 0
but doesn't the same issue exist with the SUMIFS solutions?.
Sort of. To be honest I had only really considered if the vertical criteria was not found. My suggestion does return #N/A if the horizontal condition is not found, but that is what the original construct in post 1 does too & the OP was looking for a spill option to replace that. (Did I get out of that without too much egg on my face? 😎)
 
Upvote 0
Did I get out of that without too much egg on my face?
Absolutely spotless...🙂 Yeah, the vertical no-match condition is okay with SUMIFS and problematic for FILTER, while both have issues with the horizontal no-match scenario.
 
Last edited:
Upvote 0
I like the BYROW suggestion here...I suppose you could also SUM results from some nested FILTER functions to achieve the same, shown in E2:
Book1
ABCDEFGHIJKLM
1Vertical CriteriaHorizontal CriteriaOldNewNew2CriteriaABCDEFG
2AlaskaA111111111Alaska3418452625446
3OhioC454545Hawaii15425016422210
4HawaiiE616161Alaska117244382648
5AlaskaG167167167Ohio49314039434745
6MaineB909090Maine29472718213215
7Maine2543433010331
8Ohio13135372716
9Alaska394774036426
10Alaska27352036333447
11Hawaii611211319255
Sheet3
Cell Formulas
RangeFormula
D2:D6D2=BYROW(A2:B6,LAMBDA(r,SUMIF(F2:F11,TAKE(r,,1),INDEX(G2:M11,0,XMATCH(TAKE(r,,-1),G1:M1)))))
E2:E6E2=BYROW(A2:B6,LAMBDA(r,SUM(FILTER(FILTER(G2:M11,F2:F11=TAKE(r,,1)),G1:M1=TAKE(r,,-1)))))
C2:C6C2=SUMIF($F$2:$F$11,A2,INDEX($G$2:$M$11,0,XMATCH(B2,$G$1:$M$1,0)))
Dynamic array formulas.
Hi Guys, thanks for the discussion. I see that I wasn't specific enough for my problem. These solutions would work for my case except for one key difference.

The Source array, and return array are actually a 1:1 transposition of each other (this would have been helpful I know), the dimensions of the source data and return array will not be the same of course. So if we have two criteria A and B. The source data has A vertically and B horizontally, and then the return array has A horizontally and B vertically. The SUMIF INDEX ,, MATCH pulls this off well, however it doesn't seem to spill regardless of what I feed into it.
 
Upvote 0
Could we have some smallish sample data (with the expected results filled in manually) with XL2BB and explain again in relation to that sample data? That way we can be sure we are working with the layout and type of data you are, rather that guessing. ;)
 
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,129
Members
449,097
Latest member
mlckr

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