Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Consider the following,

I have three columns,

date, sales rep, revenue,

Date,   Sales Rep,    Revenue,
1/1/18  Jon           £250
1/1/18  Evie          £350
1/1/18  Muhammad      £220

Now, to query this data I can do the following:

IF(a2="","", QUERY(B2:C4, "Select * Where A = '"&A2&"') 

now what I want to know is how one would nest multiple queries into one cell if one had multiple drop downs for the above. One selecting sales rep and one for date. So if one Selected a Sales rep & a date, they would get the specific date and sales rep but if one selected JUST a sales rep they would get all their sales regardless of date, and the reverse if possible.

I've tried an OR statement

IF(OR(a2="","", QUERY(B2:C4, "Select * Where A = '"&A2&"'), IF(a3="","", QUERY(B2:C4, "Select * Where b = '"&A3&"'))) but this didn't work. 

I've created some dummy data and an open sheet for your convenience.

https://docs.google.com/spreadsheets/d/15nlBPM9u3g0XNE3xbBgSZJxyHz2JjP9io1LfqGgX4CI/edit?usp=sharing

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
207 views
Welcome To Ask or Share your Answers For Others

1 Answer

It is easier to work on the SQL clause a piece at a time and then pull it together, I think. So for instance in J2 you could put

=if(ISBLANK(E2),"","B = '"&E2&"'")

which is either empty or a piece of the where clause.

In J3 do

=if(ISBLANK(E3),"","A = Date'"&text(datevalue(E3),"yyyy-mm-dd")&"'")

then J4 gets

=TEXTJOIN(" AND ",true,J2:J3)

and clinch with J5 as follows.

=if(isBlank(J4),"",query(A:C,"SELECT * WHERE " & J4))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...