0

I have products as columns and companies as rows, the selections are shown with the checkboxes.

sheet setup

However I am not interested in querying companies, I want to query and count the products selections and display them like this:

query result setup

What query formula should I used for this?

3
  • Yes, I need to count how many of each products were selected Commented Jul 24, 2022 at 22:06
  • Ok i got it take a look Commented Jul 24, 2022 at 22:18
  • Exact copy of Query multiple columns in Google Sheet that also has an answer. Commented Jul 25, 2022 at 6:33

3 Answers 3

1

Solution

Try this, look at this Example Sheet

Paste this formula next to products name and drag down.

=COUNTIF(FILTER($B$2:$L$16,$B$1:$L$1=N2),TRUE)

enter image description here

Explanation

FILTER the range $B$2:$L$16 where the headers $L$1 = the value in range N2:N12 products, the output is TRUE and FALSE Array.

count TRUE value in the Array resulted from FILTER with COUNTIF function COUNTIFFILTER[ True / false array ], TRUE TRUE is COUNTIF criterion.

From another tab

=COUNTIF(FILTER(Selections!$B$2:$L$16,Selections!$B$1:$L$1=B2),TRUE)

enter image description here

At a glance enter image description here


A tweek on player0 answer keep ranges open to add more values

=ARRAYFORMULA({FLATTEN(Selections!B1:L1), 
 FLATTEN(MMULT(TRANSPOSE(Selections!B2:L*1), 
 SEQUENCE(ROWS(Selections!B2:B), 1, 1, 0)))})
Sign up to request clarification or add additional context in comments.

7 Comments

Mmmh this makes sense however my dataset is in one sheet but I want to display the results in a different one: I tried this =COUNTIF(Selections!FILTER(C4:N17,C3:N3),TRUE) but it won't work.
@Pastille: You should define your problem in the main text of your question. Not in comment to an answer after the fact
As @Argyll stated take a look at Minimal, Reproducible Example to help the respondents solve the question seamlessly. he may took the time to answer you question an suddenly faced with a diffrent ask.
@Argyll Sorry! I thought I knew how to format for that case, but apparently I needed some help there as well!
@Osm Thank you! I understand there is no need to use query for this simple task :)
|
0

try:

=ARRAYFORMULA({FLATTEN(Selections!B1:L1), 
 FLATTEN(MMULT(TRANSPOSE(Selections!B2:L16*1), 
 SEQUENCE(ROWS(Selections!B2:B16), 1, 1, 0)))})

enter image description here

Comments

0

If the selection of prod 01 always reside in B2:B, why not just countif(B2:B, true) for prod 01?

For a spread-able formula, we note that you need the column index to iterate over different prod ##, but you want a summary table that is vertical. You can use indirect() to accomplish "transposed" iteration as follows. In the A1 of your other sheet, you can put

=countif(indirect("Sheet1!R2C"&(row(A1)-row(A$1)+1)&":C"&(row(A1)-row(A$1)+1),false),false) 

And you can spread vertically for the formula to retrieve counts in the subsequent columns in Sheet1.

If you move the starting cell of your summary table elsewhere, you should replace A1, A$1 in the above formula to the corresponding cell name.


The benefit of the above formula is that you are not scanning your data range unnecessarily.

Since we are mutating the formula in place, we only apply countif() to one specified column of your data at a time. For an m-by-n array, you are only doing atomic computations ~m*n times.

If you filter() your whole range per row, you multiple the amount of computations by n-fold.

If you centralize your formula by using mmult(), you multiply the amount of computations by m*n-fold -- squaring the original demand (and then scaled by a constant factor). With that, your sheet will be impractically slow way sooner than you may expect with mere a few thousand entries. Memory access would contribute to the run time delay.

Whenever you are handling a large database, only simplify your formula sparingly and cautiously.

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.