Dynamic month selection to SUMIF (Tried XLOOKUP)

Jmorrison67

Board Regular
Joined
Aug 20, 2021
Messages
52
Office Version
  1. 2016
Platform
  1. Windows
Good morning MrExcel community,

I'm looking for a bit of help with writing a formula to do a SUMIF but based on a dynamic month selection potentially embedding XLOOKUP in to it. I've created an example workbook to show you what I'm looking for.

Basically i have to SUM up values from a data set for Month but not setting the SUMIF SUM range to a particular column (as want to automate the process as much as possible and dont want the users having to move the columns range each period), but want the formula to lookup based on criteria such as: "MonthActual11" > see workbook. I'm comfortable with doing an XLOOKUP itself, but trying to get the SUMIF & XLOOKUP done is a bit tricky.

1733400984781.png


1733401251364.png


Sheet 2 is where the output / formula should be. Results for UK and USA by Month for Actual, Budget, LYA. Formula above each is then linked to the pink section which will change for each reporting period.

Sheet 1 is just the data set with the lookup formula added to it.

Tried to upload the excel but extension isnt allowed - let me know if can send it over?


Any help would be appreciated

Kind regards
Jmorrison67
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Use the following formulas, one for the UK and another for the USA, essentially it is the same formula, only the country's acronym must be placed in each formula.

varios 05dic2024.xlsm
ABCDEF
1
2Current Month
311
4
5
6
7
8
9UKActualBudgetLYA
10Month
11ActualBudgetLYA
12123abc306462600
13456def330495660
14789ghi000
15
16
17USAActualBudgetLYA
18Month
19ActualBudgetLYA
20123abc351507645
21456def375540708
22789ghi000
Sheet2
Cell Formulas
RangeFormula
D12:F14D12=SUMPRODUCT((Sheet1!$D$4:$AM$4=$B$3)*(Sheet1!$D$5:$AM$5=D$11)*(Sheet1!$B$6:$B$36=$C12)*(Sheet1!$C$6:$C$36=$C$9)*(Sheet1!$D$6:$AM$36))
D20:F22D20=SUMPRODUCT((Sheet1!$D$4:$AM$4=$B$3)*(Sheet1!$D$5:$AM$5=D$11)*(Sheet1!$B$6:$B$36=$C20)*(Sheet1!$C$6:$C$36=$C$17)*(Sheet1!$D$6:$AM$36))


🤗
 
Upvote 0
What version of Excel are you using? Your profile indicates 2016, but your screenshots look a lot like MS365.

If you have Excel for MS365, you could try the following formula in cell D12:

Excel Formula:
=LET(
    curr_mnth, B3,
    criteria1, C9,
    criteria2, C12:C14,
    crit_rng1, Sheet1!C6:C36,
    crit_rng2, Sheet1!B6:B36,
    vals, Sheet1!D6:AM36,
    cols, SEQUENCE(3,,curr_mnth*3-2),
    DROP(REDUCE("",cols,LAMBDA(a,v,HSTACK(a,SUMIFS(INDEX(vals,,v),crit_rng1,criteria1,crit_rng2,criteria2)))),,1)
)

Change the value in cell C9 from "UK" to "USA" and the results will update dynamically.

Alternatively, if the new GROUPBY function is available to you:

Excel Formula:
=GROUPBY(Sheet1!B5:B36,CHOOSECOLS(Sheet1!D5:AM36,SEQUENCE(,3,B3*3-2)),SUM,3,0,,Sheet1!C5:C36=C9)

Or, an all-in-one report with subtotals by "Site":

Excel Formula:
=GROUPBY(CHOOSECOLS(Sheet1!B5:C36,2,1),CHOOSECOLS(Sheet1!D5:AM36,SEQUENCE(,3,B3*3-2)),SUM,3,2)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,270
Members
452,902
Latest member
Knuddeluff

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