Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
watkinbt
Frequent Visitor

Saving Filters as Measures

Hello Power BI Community,

 

I frequently find myself saving filters as VARs and then applying the variable using the CALCULATE function.


See below:

 

myExpression =
VAR testFilter = FILTER(table, table[column])
RETURN CALCUALTE(SUM(table[column]),testFilter)

 

And this works really well! However, I end up re-writing the same VARs for filters in other measures. I was wondering if there was a way to save these VARs and reuse them (possibly as a measure?).

 

Appreciate any and all help!

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @watkinbt ,

As FILTER function returns a table, so you cannot save it as a measure or column, but you can save it as a new table to solve your issue, like this:

1.Create a new table.

vkalyjmsft_0-1636952692794.png

2.Create relationship.

vkalyjmsft_1-1636952692796.png

3.Directly use the new table as a filter in your DAX.

vkalyjmsft_2-1636952692798.png

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-yanjiang-msft
Community Support
Community Support

Hi @watkinbt ,

As FILTER function returns a table, so you cannot save it as a measure or column, but you can save it as a new table to solve your issue, like this:

1.Create a new table.

vkalyjmsft_0-1636952692794.png

2.Create relationship.

vkalyjmsft_1-1636952692796.png

3.Directly use the new table as a filter in your DAX.

vkalyjmsft_2-1636952692798.png

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hello @watkinbt 

You can't create a myFilter measure as it'll through an error. You may try the calculation group in this case.

Anonymous
Not applicable

Hello @watkinbt 

You don't need to use the filter. You can directly use the column within CALCULATE() without using FILTER().
MyExpression = 
CALCUALTE( SUM( table[column] ), table[column1] = "Condition" )

I could, but this doesn't really solve the issue of re-writing the conditional statement over and over again.

It would be nice if I could change this in one place (like you can with a measure). Something like:

 

myFilter = FITLER(table,table[column]="condition")

To ultimately use the filter in multiple measures like this:
measure1 = CALCULATE(SUM(table[column]),myFilter))
measure2 = CALCULATE(SUM(table[column1]),myFilter))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.