Multiplying arrays of different sized arrays

Anonymous
2022-09-23T17:55:24+00:00

Hi,

I'd like to multiply different sized array based on a condition, I've made some attempts using switch,

SUMPRODUCT(SWITCH(Table1[Item],"a",2,"b",3,"c",5,"d",6),Table1[Sales])

But this is not ideal and also I'd like to get the result for each Item, a b c and d .

I'm looking to get a total for each item, I was thinking if I could wrap the above in a IF statement,

IF( X ="a" , Sumproduct, if = "b" etc. , but the formula would still be returning the full amount.

The closest I've got so far is but the array { litems} doesn't seem to work, thought it might, so works fine for each 'a' but then I still need to sum the group?

IF(G4= {"a","b","c","d"},H4*SWITCH(G4,"a",2,"c",5,"b",3,"d",6))

could do with some fresh ideas.

Richard

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Ashish Mathur 100.9K Reputation points Volunteer Moderator
    2022-09-23T23:41:22+00:00

    Hi,

    In cell L4, enter this formula and drag down

    =SUM(FILTER($H$4:$H$16,$G$4:$G$16=J4,0)*K4)

    Hope this helps.

    1 person found this answer helpful.
    0 comments No comments
Answer accepted by question author
  1. HansV 462.4K Reputation points MVP Volunteer Moderator
    2022-09-23T18:45:26+00:00

    In the screenshot below, the formula in N4 is

    =SUMPRODUCT(Table1[Sales]*(Table1[Item]=M4),XLOOKUP(Table1[Item],Table2[Product],Table2[Price]))

    If you don't have Microsoft 365 or Office 2021, you may have to confirm the formula with Ctrl+Shift+Enter.

    1 person found this answer helpful.
    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2022-09-24T11:57:14+00:00

    Filter works as well, thanks, for the help, I do like the sumproduct version, just because it's alway been my favorite function, which I've overlooked as spend most of my time trying to do stuff with P query and pivot.

    Just to add about ctrs shift enter in 365, it can be useful when entering array formulas like the xlookup part used here into a Table, it stops the spill error.

    Richard.

    0 comments No comments
  2. Ashish Mathur 100.9K Reputation points Volunteer Moderator
    2022-09-25T01:32:23+00:00

    You are welcome.

    0 comments No comments