0

I have a table.

enter image description here

When I am using formula:

=FILTER(A1:C7,B1:B7="red",) 

what I am getting is:

enter image description here

What I would like to get however is:

enter image description here

Any ideas how to do it?

Note: Using the Filter function is a must.

2
  • I would look at unique() for column A then "red". Commented Nov 15, 2023 at 19:04
  • why not use a pivot table? Commented Nov 15, 2023 at 23:44

4 Answers 4

3

Try using the following formula:

enter image description here


• Formula used in cell E2

=LET(
     α, FILTER(A2:C7,B2:B7="red"),
     φ, INDEX(α,,1)&"|"&INDEX(α,,2),
     UNIQUE(HSTACK(TEXTBEFORE(φ,"|"),TEXTAFTER(φ,"|"),
     MMULT(N(φ=TOROW(φ)),DROP(α,,2)))))

Or, Using PIVOTBY() applicable to Beta Users

enter image description here


• Formula used in cell E2

=LET(
     α, FILTER(A2:C7,B2:B7="red"),
     PIVOTBY(TAKE(α,,2),,TAKE(α,,-1),SUM,,0))

Or Using GROUPBY()

enter image description here


=LET(α, FILTER(A2:C7,INDEX(A2:C7,,2)="red"), GROUPBY(TAKE(α,,2),TAKE(α,,-1),SUM,,0))

Or, Using PIVOTBY()

enter image description here


=PIVOTBY(A2:B7,,C2:C7,SUM,,0,,,,B2:B7="red")

Alternative version of MMULT() realized it would perform more efficiently & better than the earlier version.

enter image description here


=UNIQUE(FILTER(HSTACK(A2:B7,MMULT((A2:A7=TOROW(A2:A7))*(B2:B7="red"),C2:C7)),B2:B7="red"))

Sign up to request clarification or add additional context in comments.

2 Comments

I am not a Beta User. So GROUPBY() or PIVOTBY() are not available to me. But the very first option worked for me. Thank you! I hope GROUPBY() or PIVOTBY() are released to official version asap.
The MMULT() should work, also I have just posted that as an alternative, I have found there are some issues with those functions for now, should nt be used as it is in Beta testing. shared as a knowledge purpose. Yes usually all new functions are released by batches as far I have learnt from experts! And not just that in workplace Beta will not be allowed to be enabled, usually unless there is a special grant for the same!
2

Similar to Mayukh Bhattacharya's answer, but without text manipulation.

=LET(
    valid_range, FILTER(A2:C7, B2:B7="red"),
    values, MMULT(TRANSPOSE(INDEX(valid_range,,1) = TRANSPOSE(UNIQUE(INDEX(valid_range,,1))))*1, 
INDEX(valid_range,,3)),
    HSTACK(UNIQUE(DROP(valid_range,,-1)), values))

Comments

2

If applicable, use GROUPBY():

enter image description here

Formula in E2:

=GROUPBY(A2:B7,C2:C7,SUM,,0,,B2:B7="red")

You say using FILTER() is a must, however we have now used the internal groupby-filter which seems fine to me.


Alternatively, "old"-fashioned:

=UNIQUE(FILTER(HSTACK(A2:B7,SUMIFS(C2:C7,A2:A7,A2:A7,B2:B7,"red")),B2:B7="red"))

2 Comments

GROUPBY() is a function for BETA users only. Many still don't have access to BETA (especially if it's a corporate Excel).
@Elmar, absolutely, however you have many alternatives. Anyway; I have also edited in an alternative using old-fashioned SUMIFS().
1

For those having access to Beta version of Excel:

=LET(f,FILTER(A2:C7,B2:B7="red"),PIVOTBY(TAKE(f,,2),,DROP(f,,2),SUM,,0))

or =LET(f,FILTER(A2:C7,B2:B7="red"),GROUPBY(TAKE(f,,2),DROP(f,,2),SUM,,0)) or =LET(g,GROUPBY(A2:B7,C2:C7,SUM,,0),FILTER(g,INDEX(g,,2)="red"))

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.