Adding variables on joined table

Hi,

On a native SQL-query I want to add variables from a joined table to be able to filter on query and dashboard.

SELECT datefromparts(year("dbo"."orderrow"."expecteddate"), month("dbo"."orderrow"."expecteddate"), 1) AS "date", sum("dbo"."orderrow"."totalrestvalue") AS "sum1"
FROM "dbo"."orderrow"
LEFT JOIN "dbo"."order" "o" ON "dbo"."orderrow"."order" = "o"."idorder"
LEFT JOIN "dbo"."company" "c" ON "o"."company" = "c"."idcompany"
LEFT JOIN "dbo"."coworker" "co" ON "c"."coworker" = "co"."idcoworker"
WHERE datefromparts(year("dbo"."orderrow"."expecteddate"), 1, 1) = datefromparts(year(getdate()), 1, 1)
AND "dbo"."orderrow"."expecteddate" IS NOT NULL
[[AND {{Land}}]]
[[AND {{Kund}}]]
[[AND {{Coworker}}]]
[[AND {{Region}}]]
[[AND {{Area}}]]
[[AND {{Datum}}]]
GROUP BY datefromparts(year("dbo"."orderrow"."expecteddate"), month("dbo"."orderrow"."expecteddate"), 1

I can filter on variables from table orderrow, but not from company or order.
For example [[AND {{Region}}]] is a variable on the company table. When I try to filter on that I get an error message saying "The multi-part identifier "dbo.company.limeregion" could not be bound".

Is it possible to filter on variables from the joined table and if so how do I do that?

Hi @aminademirovic
You cannot use table aliases, when using Field Filters:
https://www.metabase.com/learn/building-analytics/sql-templates/field-filters.html#field-filter-gotchas

Worked when I removed the alias. Thank you so much!! :slight_smile: