Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
111 views
in Technique[技术] by (71.8m points)

How to Pivot with multiple WHERE AND and OR conditions with Query function in Google Sheets

Goal: I want to create a pivot table with the QUERY function while using I have multiple criteria (using ANDs and ORs at the same time). The table basically consists of 2 columns: Col C is "Employee," Col B is "Status." The values for Status contains: "In Progress" "Consultation" "Require Information" and "Technical Issue." And there are multiple employee names that I won't bother listing. And I wanted it to basically count the number of statuses each employees have.

Now, I actually had a functional formula that was working well, however I wanted to add another criteria, which was to exclude (filter) one particular employee (let's say this person's name is "John A") from the result. And I want to be able to keep the criteria that I currently have and just add the new one. The formula before the modification is below.

Formula before modification:

=QUERY('Blend Data'!$A$3:$C,"select C, COUNT(C) where (B = 'In Progress' OR B = 'Consultation' OR B = 'Require Information' OR B = 'Technical Issue') GROUP BY C pivot B",0)
question from:https://stackoverflow.com/questions/65871893/how-to-pivot-with-multiple-where-and-and-or-conditions-with-query-function-in-go

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

1 Reply

0 votes
by (71.8m points)

try:

=QUERY('Blend Data'!A3:C,
 "select C,count(C) 
  where B matches 'In Progress|Consultation|Require Information|Technical Issue' 
    and C = 'John A' 
  group by C 
  pivot B", 0)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...