Reputation: 961
As you can see I wish to count how many days each product has been shorted. The amount shorted is not relevant just the amount of days shorted. Salad saw two days shorted, cheese saw no days and Trifle saw 1 day with shorts. I just can't work out the formula to put into column "I" to automatically calculate days shorted.
Upvotes: 2
Views: 185
Reputation: 585
=LET(
data, A2:D25,
p, CHOOSECOLS(data, 1),
d, CHOOSECOLS(data, 2),
s, CHOOSECOLS(data, 4),
one, MAP(
UNIQUE(p),
LAMBDA(m, IFERROR(ROWS(UNIQUE(FILTER(d, (p = m) * s))), 0))),
two, HSTACK(UNIQUE(p), one),
two
)
Upvotes: 0
Reputation: 1282
In cell I1
, use the following formula, then copy it down:
=SUM(--(SUMIFS($D$2:$D$25, $A$2:$A$25, H1, $B$2:$B$25, UNIQUE($B$2:$B$25))>0))
OR, to make it spill down automatically, use:
=BYROW(H1:H3, LAMBDA(r,
SUM(--(SUMIFS(D2:D25, A2:A25, r, B2:B25, UNIQUE(B2:B25))>0))))
OR, if cell H1
is already dynamic with =UNIQUE(A2:A25)
, then use:
=BYROW(H1#, LAMBDA(r,
SUM(--(SUMIFS(D2:D25, A2:A25, r, B2:B25, UNIQUE(B2:B25))>0))))
OR, to include everything in one array, use:
=LET(
list, UNIQUE(A2:A25),
HSTACK(list, BYROW(list, LAMBDA(r,
SUM(--(SUMIFS(D2:D25, A2:A25, r, B2:B25, UNIQUE(B2:B25))>0))))))
Cheers!
Upvotes: 2
Reputation: 11468
Using MMULT (twice) you could spill it in one go:
=LET(u,UNIQUE(A2:B25),
p,TAKE(u,,1),
m,MMULT((TOROW(A2:A25)=p)*(TOROW(B2:B25)=INDEX(u,,2)),N(D2:D25>0)),
q,UNIQUE(p),
HSTACK(q,MMULT(N(TOROW(p)=q),N(m>0))))
Upvotes: 0
Reputation: 6177
Put this formula in I1 and press CTRL-SHIFT-ENTER (array formula)
=SUM(IF(UNIQUE(IF(IF(A$2:A$25=$H1,1,0)*D$2:D$25>0,B$2:B$25,0))>0,1,0))
Drag to the end of column H, where the Product names are.
Upvotes: 1