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

Join 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.

Reply
RMDNA
Solution Sage
Solution Sage

Store filter criteria as a string in a variable so I don't have to keep typing it

Hi all, hopefully quick question here. I'm writing some simple statements in DAX Studio like:

CALCULATE(COUNTROWS(Table),Category1 = "Value',Category2 = "Value2") = 100

This works fine, but I don't want to keep typing my filters (Cat1=, Cat2=,etc.) over and over again. Can I somehow capture that into a string and just use that in my post-calculate filter statements? I'd like to set up a bunch of filters at the start of the statement and just reference them throughout the rest of the script. E.g.:

VAR filter_criteria = (Category1 = "Value',Category2 = "Value2")
EVALUTE
CALCULATE(COUNTROWS(Table),filter_criteria) = 100

 Or am I missing an easier solution?

1 ACCEPTED SOLUTION
Dangar332
Super User
Super User

Hi, @RMDNA 

Try below measure

 

EVALUTE
var filter_criteria= filter(table,Category1 = "Value'&& Category2 = "Value2" && category3="Value3"&&....)
return
CALCULATE(COUNTROWS(Table),filter_criteria)

 



 

Best regards,
Dangar 

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

3 REPLIES 3
Dangar332
Super User
Super User

Hi, @RMDNA 

Try below measure

 

EVALUTE
var filter_criteria= filter(table,Category1 = "Value'&& Category2 = "Value2" && category3="Value3"&&....)
return
CALCULATE(COUNTROWS(Table),filter_criteria)

 



 

Best regards,
Dangar 

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

Hi @Dangar332 - what if I wanted to filter on multiple tables? E.g.

 

(Table1[Field1] = x, Table2[Field2] = y || Table2[Field2] = z)

 

Since they included filtering as a native ability of Calculate, I've stopped using the actual Filter function for a long time. I believe it can only accept a single table as a reference. Do I need to nest Filters? Seems inefficient.

Hi, @RMDNA 

You can use Crossjoin ()

filter(
crossjoin(
values(Table1[Field1]),
values( Table2[Field2])
),
Table1[Field1] = x && Table2[Field2] = y)

 

Best regards,
Dangar 

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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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