Forum Discussion
COUNTIFS / SUMPRODUCT + OR Alternative?
Table1 columns: A - Order (order number), B - Customer (name), C - Date (shipped), D - Pc (number of boxes shipped)
Table2 columns: F - Jan23 (January 2023 dates) through K - Jun23 (June 2023 dates)
Table3 columns: M and N - MonO/MonB (orders/boxes shipped any Monday) through U and V - FriO/FriB (orders/boxes shipped any Friday)
Table4 columns: X and Y - 1O/1B (orders/boxes shipped on days 1-10), Z and AA - orders/boxes shipped on days 11-20, AB and AC - orders/boxes shipped on days 21-31
Column AE - AOC (all unique customers in alphabetical order)
All tables/columns have a header line; data begins on line 2
First, I tried my hand at a formula for column M (to also be modified and used in O, Q, S, and U) which ended up looking something like:
=COUNTIFS(Table1[Customer],$AE2,Table1[Date],OR($F$3,$F$10,$F$17,$F$24,$F$31,$G$7,$G$14,$G$21,$G$28,$H$7,$H$14,$H$21,$H$28,$I$4,$I$11,$I$18,$I$25,$J$2,$J$9,$J$16,$J$23,$J$30,$K$6,$K$13,$K$20,$K$27))
However, I soon learned that OR cannot be used inside the COUNTIFS formula. So I started looking elsewhere. I found partial answers, I found things I thought would work but didn't...so I come here in hopes someone can help me throw things together to make this work. I was even hoping that some fix like using WEEKDAY would be able to help, but nothing so far.
In a similar vein, I tried writing a formula for column N (to also be modified and used in P, R, T, and V); this one ended up looking something like:
=SUMIFS(Table1[Pc],Table1[Customer],$AE2,Table1[Date],OR($F$3,$F$10,$F$17,$F$24,$F$31,$G$7,$G$14,$G$21,$G$28,$H$7,$H$14,$H$21,$H$28,$I$4,$I$11,$I$18,$I$25,$J$2,$J$9,$J$16,$J$23,$J$30,$K$6,$K$13,$K$20,$K$27))
I ran into the same issue with SUMIFS that I did with COUNTIFS; it can't use OR.
Any sort of assistance would be greatly appreciated!
If you use VSTACK rather than OR you will get an array of counts which you could aggregate with SUM or OR
= SUM(COUNTIFS(Table1[Customer], selected, Table1[Date], VSTACK(J3, F4,I5, K7, G8, H8))) = OR(COUNTIFS(Table1[Customer], selected, Table1[Date], VSTACK(J3, F4,I5, K7, G8, H8)))
3 Replies
- PeterBartholomew1Silver Contributor
If you use VSTACK rather than OR you will get an array of counts which you could aggregate with SUM or OR
= SUM(COUNTIFS(Table1[Customer], selected, Table1[Date], VSTACK(J3, F4,I5, K7, G8, H8))) = OR(COUNTIFS(Table1[Customer], selected, Table1[Date], VSTACK(J3, F4,I5, K7, G8, H8)))
- and_rogynousCopper ContributorThe first formula worked perfectly! I was able to get it functioning for every line and each day of the week.
The second formula doesn't incorporate a final thing that I seem to have forgotten to mention - the values in Table1[Pc] are not all 1; they show the number of boxes shipped, so I'd need each of the amounts added together. That's why I tried SUMIFS instead of COUNTIFS in the original example. Is there a possible fix for that?
Thank you again!- PeterBartholomew1Silver Contributor
I have only had a quick glance but I see no reason to believe that SUMIFS couldn't be used in place of COUNTIFS provided you insert the additional range reference to the data to be summed. That would return and array which would itself need to be summed as before.