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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

'IN' Operator in 'New Measure'

HI,

How to write following code in dax Measure ?

if ( Column1 in ("Value1","Value2"...."ValueN") then [Revenue] else 0)

 

I am struggling here: I am able to give it like this

if ( Column1 ="Value1" or Column1 ="Value2".... or Column1 ="ValueN") then [Revenue] else 0)

which is not efficient...

is there any function that i can use... instead of 'IN' operator...??

 

I need  calculate( sum(FactT[revenue]), filter(FactT,FactT[Column1]  in ("Value1","Value2"...."Value3")))

 

I am able to do like this:  calculate( sum(FactT[revenue]), filter(FactT,FactT[Column1] = "Value1" || FactT[Column1] = "Value2"... || FactT[Column1] = "Value1")) 

Thanks in advance.

1 ACCEPTED SOLUTION
radpir
Resolver II
Resolver II

hi,

 

you would need to put the values you want in the IN predicates into a separate table i.e. PREDICATES.

 

here's the sample setup that i created to illustrate this case:

 

FactT  PREDICATES
CategoryAmount Column1Values_IN
Value1100 Value1
Value150 Value2
Value210 Value3
Value220  
Value230  
Value310  
Value440  
Value390  
Value41000  
Value4500  
Value5432  
Value6593  
Value6876  

 

and then you could use this formula:

 TotalAmt_IN =

               CALCULATE ( SUM('FactT'[Revenue]),

                       FILTER ( 'FactT', CONTAINS(PREDICATES, PREDICATES[Column1Values_IN], 'FactT'[Column1] ) )

                 )

 

the formula returns 310 based on the above data.

 

hope this helps,

 

radpir

View solution in original post

1 REPLY 1
radpir
Resolver II
Resolver II

hi,

 

you would need to put the values you want in the IN predicates into a separate table i.e. PREDICATES.

 

here's the sample setup that i created to illustrate this case:

 

FactT  PREDICATES
CategoryAmount Column1Values_IN
Value1100 Value1
Value150 Value2
Value210 Value3
Value220  
Value230  
Value310  
Value440  
Value390  
Value41000  
Value4500  
Value5432  
Value6593  
Value6876  

 

and then you could use this formula:

 TotalAmt_IN =

               CALCULATE ( SUM('FactT'[Revenue]),

                       FILTER ( 'FactT', CONTAINS(PREDICATES, PREDICATES[Column1Values_IN], 'FactT'[Column1] ) )

                 )

 

the formula returns 310 based on the above data.

 

hope this helps,

 

radpir

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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