Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
The following formula works, but I'm trying to better the approach a little since strings around it can change dynamically at the source, but the integer code pertaining to a category (233333, 455555 in the below example) will not.
Current formula :
Solved! Go to Solution.
You cannot put a true/false statements under CALCULATE. There are very specific conditions that can be written like this but they really are not true/false statements since the engine expands them automatically into tables. Because - let me reiterate it - only tables can be filters under CALCULATE. So, instead of CONTAINS in there you should turn it into a filter on a table and put the table instead. But I think you should use a different function here, CONTAINSSTRING, like so:
CALCULATE(
[Total Time],
FILTER(
VALUES( 'Fact Table'[Category] ),
OR(
CONTAINSSTRING(
'Fact Table'[Category],
"310251"
),
CONTAINSSTRING(
'Fact Table'[Category],
"320251"
)
)
)
)
Thank you. Can you explain your logic behind using VALUES function here?
Since I was thinking along the lines of :
You cannot put a true/false statements under CALCULATE. There are very specific conditions that can be written like this but they really are not true/false statements since the engine expands them automatically into tables. Because - let me reiterate it - only tables can be filters under CALCULATE. So, instead of CONTAINS in there you should turn it into a filter on a table and put the table instead. But I think you should use a different function here, CONTAINSSTRING, like so:
CALCULATE(
[Total Time],
FILTER(
VALUES( 'Fact Table'[Category] ),
OR(
CONTAINSSTRING(
'Fact Table'[Category],
"310251"
),
CONTAINSSTRING(
'Fact Table'[Category],
"320251"
)
)
)
)
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
11 | |
10 | |
9 | |
8 |
User | Count |
---|---|
17 | |
12 | |
11 | |
11 | |
11 |