excelexcel-formulasumifsnamed-ranges

Dynamically Switching a Range in a SUMIF()


I have a formula in excel that looks like this:

=SUMIFS(SILOADRESERVED,
    SIPDU,
    B8&"*",
    SIPHASE, "A",
    SITYPE, "<>RMT"
)

The challenge is that SIPDU range changes for different phases of the project, so I'd like to replace it with a different range depending on the outcome of a conditional, like below. If the phase we're interested in at AJ4 is less than the changeover phase for this element, the SUMIF search should be performed on the old range SIPDU, but if the phase has already happened, the SUMIF search should be performed on the new range, SI_NEW_PDU. These named ranges are adjacent columns of equal length.

=SUMIFS(SILOADRESERVED,
    IF($AJ$4<MD_Main_Changeover_Phase, SIPDU, SI_NEW_PDU),
    B8&"*",
    SIPHASE, "A",
    SITYPE, "<>RMT"
)

However, I'm receiving a SPILL error, and I'm not sure how to proceed. I'm using Office 365.

Some other approaches I tried that did not work:

=SUMIFS(SILOADRESERVED, INDEX((SIPDU, SI_NEW_PDU), MATCH($AJ$4<MD_Main_Changeover_Phase, {TRUE, FALSE}, 0)), B8&"*", SIPHASE, "A", SITYPE, "<>RMT")

=SUMIFS(SILOADRESERVED, CHOOSE(($AJ$4<MD_Main_Changeover_Phase)+1, SIPDU, SI_NEW_PDU), B8&"*", SIPHASE, "A", SITYPE, "<>RMT")

I'm thinking the problem is that SUMIFS iterates over every row, but the $AJ$4<MD_Main_Changeover_Phase is nested inside the IF, so the MD_Main_Changeover_Phase isn't getting iterated over at the same time. I'm not sure how to get around this though.

I'm afraid to use helper columns, since this same problem occurs for eight different named ranges in my project, not just SIPDU. Each row in my data set represents an electrical load, with two sources, and the sources are stored across four columns (like an address). We are doing a phased project where we transition the loads to two new sources, but not necessarily during the same phase. So we are trying to track the loads during this transition. Four named ranges will be adjusted based on one phase range; the other four will be controlled based on a second phase range.

Edit: Here's a simpler example of what I'm trying to achieve with the results I need on the right. You can manually adjust the Current Phase to update the SUMIFS below.

enter image description here

Here's the same data in a copyable CSV format for others to use:

Equipment ID Load Old PDU New PDU Phase that we switch device over
1 5 A D 1
2 5 A E 1
3 10 B F 2
4 10 B F 3
5 20 C H 4
Current Phase 2
Load on PDU A 0
Load on PDU B 10
Load on PDU C 20
Load on PDU D 5
Load on PDU E 5
Load on PDU F 10

Solution

  • Here is one way of solving the query:

    enter image description here


    =MAP(G2:G7, LAMBDA(α, 
     SUM((IF(H$1<E2:E6,C2:C6,D2:D6)=
     TEXTAFTER(α," ",-1))*B2:B6)))