Forum Discussion
FILTER function query
Hi,
I'm trying to find the value of SalesAmount for all products with "SQLBI" brand or color "Red" while not altering filters in other columns (It's a question on the sqlbi website).
I know this statment is correct:
Calculate (
[SalesAmount],
FILTER (
ALL (
Product[Color],
Product[Brand]
),
Product[Color] = "Red" || Product[Brand] = "SQLBI"
)
)But please can you tell me why the code below is wrong? I thought that the line Product[Color] = "Red" || Product[Brand] = "SQLBI" would automatically override any filters for Product[Color] and Product[Brand]? So the two snippets of code would be equivalent?
CALCULATE (
[SalesAmount],
FILTER (
Product,
Product[Color] = "Red" || Product[Brand] = "SQLBI"
)
)
Thanks for any help,
CM
5 Replies
- StachuCommunity Champion
I think it's best to show by example, take table like this:
Color Brand Amount Red SQLBI 1 Red SQLBI 1 Red A 1 Red B 1 Blue SQLBI 1 Blue A 1 Green B 1 the measures return following results:
let's take the first row in incorrect - unmodified filter context is Color = Blue && Brand = A
Which is effectively just 1 row table that looks like this:table like this:
Color Brand Amount Blue A 1 the numbers of rows that are Red or SQLBI in this table = 0, hence blank
So ALL allows to get the value that's visible in the Total row, rather than one that is specific to partivular filter context
hope that helps
- AnonymousNot applicable
Thank you Stachu , is it correct to say that an OR statement doesn't override the existing filter context, but normal statments like the two below (without the "OR" condition) do override the existing filter context?
Product[Color] = "Red",
Product[Brand] = "SQLBI"
Many Thanks,
CM
- StachuCommunity Championactually my explanation is not accurate, I got very confused because of the multiple columns this article does a good job explaining what's happening in the back https://www.sqlbi.com/articles/filter-arguments-in-calculate/