Looker API handling OR condition

Hi team,
I need to get SQL query from Looker API with OR condition

json body:

 

{
"metric_name":"line_dep_cat",
"model":"looker_project",
"view":"digital_line",
"fields":["line.line_set*"],
"filters":{
"line.event_date":"2024-09-01 to 20204-09-10"
"line.department":"2", 
"line.category":"111"
}
}

 

The request builds query:

 

SELECT event_dt, department, category
FROM dv.line_daily
WHERE (event_dt) >= DATE('2024-09-01') AND (event_dt) < DATE('2024-09-10') AND (department='2') AND (category='111')

 

Need to get the following SQL query

 

SELECT event_dt, department, category
FROM dv.line_daily
WHERE (event_dt) >= DATE('2024-09-01') AND (event_dt) < DATE('2024-09-10') AND ((department='2') OR (category='111'))

 

Thanks for your help!

Solved Solved
0 2 309
1 ACCEPTED SOLUTION

I kind of reverse-engineered this and built an explore with an 'or' condition (which you can do in the filters window now by creating a new 'group' of filters). Then I ran 'get query for slug' in the API to see how it expressed the 'or' condition. It turns out it uses 'filter expression' rather than 'filters' to build this. You can see what it looks like below:

"filter_expression": "(matches_filter(${order_items.created_month}, `1 months`) AND matches_filter(${orders.gender}, `M`)) OR (matches_filter(${products.category}, `Active`))",

View solution in original post

2 REPLIES 2

I kind of reverse-engineered this and built an explore with an 'or' condition (which you can do in the filters window now by creating a new 'group' of filters). Then I ran 'get query for slug' in the API to see how it expressed the 'or' condition. It turns out it uses 'filter expression' rather than 'filters' to build this. You can see what it looks like below:

"filter_expression": "(matches_filter(${order_items.created_month}, `1 months`) AND matches_filter(${orders.gender}, `M`)) OR (matches_filter(${products.category}, `Active`))",

Thank you @GavinW ! That will work for me