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.
Hello,
Would anyone know if I can apply an if statement to whether or not the calculate function applies a filter? As an example, I'm trying to say,
test =
VAR _Category = SELECTEDVALUE ( 'Table1'[VALUE] )
RETURN
CALCULATE ( SUM ( 'Table2'[TOTAL SAVINGS] ),
IF ( _Category <> "All",
FILTER ( 'Table2', [CATEGORY] = _Category ),
ALLSELECTED ( 'Table2'[CATEGORY] )
)
)
However, I get an error saying "A Function "FILTER" has been used in a True/False experssion that is used as a table filter expression. That is now allowed".
Is there a way to only use filter with a calculate function when a condition is met?
Solved! Go to Solution.
How about this formula below?
test =
VAR _Category = SELECTEDVALUE ( 'Table1'[VALUE] )
RETURN
IF ( _Category <> "All",
SUMX ( FILTER('Table2', 'Table2'[CATEGORY] = _Category), 'Table2'[TOTAL SAVINGS] ),
CALCULATE ( SUM ( 'Table2'[TOTAL SAVINGS] ), ALLSELECTED ( 'Table2'[CATEGORY] ))
)
How about this formula below?
test =
VAR _Category = SELECTEDVALUE ( 'Table1'[VALUE] )
RETURN
IF ( _Category <> "All",
SUMX ( FILTER('Table2', 'Table2'[CATEGORY] = _Category), 'Table2'[TOTAL SAVINGS] ),
CALCULATE ( SUM ( 'Table2'[TOTAL SAVINGS] ), ALLSELECTED ( 'Table2'[CATEGORY] ))
)
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 |
---|---|
56 | |
55 | |
54 | |
37 | |
29 |
User | Count |
---|---|
78 | |
64 | |
45 | |
40 | |
40 |