Forum Discussion

ravanwijk's avatar
ravanwijk
Copper Contributor
Nov 30, 2021
Solved

SUMIFS with OR Logic and spilling results

Hi, I am looking for a way to design a formula that can fill a table by spilling the result. The formula is composed of a sum that requires to meet certain conditions (Logic AND + Logic OR). Once I ...
  • SergeiBaklan's avatar
    Nov 30, 2021

    ravanwijk 

    I tried to combine all in one spill

    with

    =IFERROR(
        LET(
            select, FILTER(B16#, $B$17:$D$17 <> ""),
            c, COLUMNS(select),
            fSel, MMULT(--(select = dB[Forecast]), SEQUENCE(c, , 1, 0)) * dB[Incl],
            uMonths, SORT(UNIQUE(FILTER(dB[Month], fSel))),
            uRegions, TRANSPOSE(SORT(UNIQUE(FILTER(dB[Region], fSel)))),
            nRegions, COLUMNS(uRegions),
            nMonths, ROWS(uMonths),
    
            data, MMULT(
                --(uMonths = TRANSPOSE(dB[Month])),
                (uRegions = dB[Region]) * dB[Value]
            ),
            total, MMULT(data, SEQUENCE(nRegions, , 1, 0)),
    
            k, SEQUENCE(nMonths + 1, nRegions + 2),
            kR, INT((k - 1) / (nRegions + 1 + 1)) + 1,
            kC, MOD(k - 1, nRegions + 1 + 1) + 1,
            IF(
                kR = 1,
                IF(
                    kC = 1,
                    "R/M",
                    IF(kC = nRegions + 2, "Total", INDEX(uRegions, kC - 1))
                ),
                IF(
                    kC = 1,
                    INDEX(uMonths, kR - 1),
                    IF(
                        kC = nRegions + 2,
                        INDEX(total, kR - 1),
                        INDEX(data, kR - 1, kC - 1)
                    )
                )
            )
        ),
        "no data"
    )

Resources