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
Nie
Helper I
Helper I

Check Values in Column Against List

I want to write a measure to check if a column contains certain numerical values that I specify. These values are something like "2022, 2021, 2019" and may change.

 

I looked at various formulas and it looks like CONTAINS(Table, ColumnName, Value) can be used for this. But how do I specify something like {2022, 2021, 2019} in the Value argument? I want to store this as a variable so that it can be changed easily later instead of writing extensive if else statements.

 

If CONTAINS is in fact not suitable, I would appreciate an alternative solution. I've looked for hours and couldnt find anything similar to m code's List.ContainsAny({1, 2, 3, 4, 5}, {3, 9}).

 

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

Hi @Nie ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1669712939996.png

(2) Create a parameter of type number.

vtangjiemsft_1-1669713188672.png

vtangjiemsft_2-1669713209431.png

 

(3) Then we can create a measure.

Measure = 
var _a = SELECTCOLUMNS('Parameter',"Value",[Parameter])
var _b = ADDCOLUMNS(_a,"Flag",IF([Value] in SELECTCOLUMNS('Table',"Target",[Column1]),1,0))
var _c = COUNTX(_a,[Value])
return SUMX(_b,[Flag])=_c

(4)Then the result is as follows.

vtangjiemsft_3-1669713422567.png

Best Regards,

Neeko Tang

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

2 REPLIES 2
v-tangjie-msft
Community Support
Community Support

Hi @Nie ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1669712939996.png

(2) Create a parameter of type number.

vtangjiemsft_1-1669713188672.png

vtangjiemsft_2-1669713209431.png

 

(3) Then we can create a measure.

Measure = 
var _a = SELECTCOLUMNS('Parameter',"Value",[Parameter])
var _b = ADDCOLUMNS(_a,"Flag",IF([Value] in SELECTCOLUMNS('Table',"Target",[Column1]),1,0))
var _c = COUNTX(_a,[Value])
return SUMX(_b,[Flag])=_c

(4)Then the result is as follows.

vtangjiemsft_3-1669713422567.png

Best Regards,

Neeko Tang

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

Thank you Neeko!

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.