Is there a way to use a single variable to filter two or more fields/columns?
Example:
SELECT
(SELECT SUM(“MOVPDV”.“VALOR”) AS “VALOR”
FROM “MOVPDV”
WHERE {{date_range}} AND “MOVPDV”.“MOVTO” = ‘VE’) -
(SELECT SUM(“DEVOLUC”.“VALOR”) AS “VALOR”
FROM “DEVOLUC”
WHERE {{date_range}}) AS “VENDAS”
I wish to use a single date selector {{date_range}} to filter “MOVPDV”.“DATA” and “DEVOLUC”.“EMISSAO”.
Hi @coutoreis
You cannot use Field Filters with aliases, so since it’s two different tables, then it would not be possible.
Go and upvote this issue by clicking
on the first post:
https://github.com/metabase/metabase/issues/3324
@flamber
Oh, I’m kinda frustrated here. I need to calculate the profit based in one table (sellings) minus other table (devolutions/cancelations). That’s what the code I posted is for. Is there any workaround to filter the date in both tables?
Ps.: I upvoted the referenced issue.
@coutoreis
You should be able to do something with sub-queries, if you don’t want to use two simple Date filters. There’s an example in the issue: https://github.com/metabase/metabase/issues/3324#issuecomment-416140719
1 Like
Hi @coutoreis
I had a similar issue here.
I didn’t know the name sub-query before the @flamber’s post, but it really works for in my case.