Brianna Eisermann
Brianna Eisermann

Reputation: 21

Is there a way to prevent duplicates in an array with stacked queries in Google Sheets?

I'm trying to create a simple sort feature in Google Sheets by having data validation drop-down lists and using an array of queries. I can get it to work but if a row matches more than one of the data validation drop down lists, then it will appear twice in the array.

I have tried using vlookup instead but don't really understand how that works as I can only find very specific examples. I have tried using "=ARRRAYFORMULA" and putting my queries inside there but that does not solve the issue either.

My cell currently is

={ IF(NOT(ISBLANK(B2)),
    QUERY('App Data Sheet'!1:1006, " select * where B = '"&B2&"'", 0), "");
   IF(NOT(ISBLANK(C2)), 
    QUERY('App Data Sheet'!1:1006, " select * where C = '"&C2&"'", 0), "")
}

where B2 and C2 are data validation cells in the active sheet.

You can view my Query Sheet here: https://docs.google.com/spreadsheets/d/1AgvDIjmn2tv9_zKj7o5MPYZ9CdX9mZ_tM66n5jp5NEY/edit?usp=sharing

I currently only have two drop-down lists but will want to add more later once I figure out the duplicates issue.

EDIT: I know that you can use countif to see if there are duplicates in a range but I do not how to enter that into my code to prevent it from showing.

EDIT2:

Well, I figured it out. I simply needed to encapsulate my formula inside a =UNIQUE() function that I had not known about before. Hopefully, this post will still help someone else out.

Upvotes: 0

Views: 42

Answers (1)

Brianna Eisermann
Brianna Eisermann

Reputation: 21

Well, I figured it out. I simply needed to encapsulate my formula inside a =UNIQUE() function that I had not known about before. Hopefully, this post will still help someone else out.

Googling using the proper words is what made a big difference in finding a solution. Instead of saying that I wanted to prevent duplicates, I searched to only show unique rows.

Upvotes: 1

Related Questions