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
Naveen_SV
Helper IV
Helper IV

How to Assign set of text value to one variable name and filtering them

HI All,

 

I am looking for a solution in dax to assign set of value to a variable like

Animals = "Cat","Dog","Elephant"

Plant = "Sherb","Herb", "Moss"

Can anyone please help me with this.

2 ACCEPTED SOLUTIONS

Hi @Naveen_SV ,

 

Please try to change the FilterTable in formula to your new table name

 

IsInFilters =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        'Table'[Column1] IN FILTERS ( 'FilterTable'[Column1] )
            || 'Table'[Column2] IN FILTERS ( 'FilterTable'[Column1] )
    )
)

 

to

 

IsInFilters =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        'Table'[Column1] IN FILTERS ( 'Table 2'[Column1] )
            || 'Table'[Column2] IN FILTERS ( 'Table 2'[Column1] )
    )
)

 


Best regards,


 

Community Support Team _ Dong Li
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

Hi @Naveen_SV ,

 

We can try to generate the filtertable as following:

 

FilterTable =
FILTER (
    DISTINCT (
        UNION ( DISTINCT ( 'Table'[Column1] ), DISTINCT ( 'Table'[Column2] ) )
    ),
    [Column1] <> BLANK ()
        && [Column1] <> ""
)


Best regards,

 

Community Support Team _ Dong Li
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

13 REPLIES 13
v-lid-msft
Community Support
Community Support

Hi @Naveen_SV ,

 

We can use {"Value1", "Value2", .... , "Value10"} to include  the constant values into a var

 

ConstantVar = var t = {"Cat","Dog","Elephant"}
return CONCATENATEX(t,[Value]," & ")

 

Or we can use SelectedColumn to get them from a table

 

 

DynamicVar = var t = SELECTCOLUMNS('Table',"Value",[Name])
return CONCATENATEX(t,[Value]," & ")

 

6.jpg

 

 
If it doesn't meet your requirement, Please show the exact expected result based on the Tables that you have shared.


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

HI @v-lid-msft 

 

Below is the screen shot i am looking at where i need to select "without car" and "with car" in a single filter if i select without car it should select "In progress", "Assigned" and "Closed" and if is elect with Car it should select only "Assigned " and "Closed"

 

 

test1.PNG

 

 Annotation 2019-12-19 1206031.png

Hi @Naveen_SV ,

 

First of all, we can create a spreate calculate table as filter.

 

FilterTable = DISTINCT(UNION(DISTINCT('Table'[Column1]),DISTINCT('Table'[Column2])))

 

Then we can use a measure in visual filters to meet your requirement 

 

IsInFilters = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Column1] in FILTERS('FilterTable'[Column1]) || 'Table'[Column2] in FILTERS('FilterTable'[Column1])))

 

9.jpg10.jpg

 


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

HI @v-lid-msft 

Thanks for your reply

how did you create this Table when i am recreating it i am unable to write that formuale.

 

bug4.PNG

Hi @Naveen_SV ,

 

Please try to create a calculated table for "Filter Table" and a measure for "IsInFilters".

 

1.jpg

 


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-lid-msft 

 

This is something unforutnate i am unable to recreate your logic when i tried recreating a new table in your PBi file

with the same formulae in the column it's not gettting filtered. 

 

bug5.PNG

hi @v-lid-msft 

 

bug6.PNG

Hi @Naveen_SV ,

 

Based on the sample table, the without car should have three status, have you tried to filter by with car?


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-lid-msft 

Thanks for your responcse

 

Please try creating it in your PBI file it's shows the same issue.

Hi @Naveen_SV ,

 

Please try to change the FilterTable in formula to your new table name

 

IsInFilters =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        'Table'[Column1] IN FILTERS ( 'FilterTable'[Column1] )
            || 'Table'[Column2] IN FILTERS ( 'FilterTable'[Column1] )
    )
)

 

to

 

IsInFilters =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        'Table'[Column1] IN FILTERS ( 'Table 2'[Column1] )
            || 'Table'[Column2] IN FILTERS ( 'Table 2'[Column1] )
    )
)

 


Best regards,


 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-lid-msft 

 

Thanks a lot its working now.

 

if i want to hide blank in that how can i do that.

Hi @Naveen_SV ,

 

We can try to generate the filtertable as following:

 

FilterTable =
FILTER (
    DISTINCT (
        UNION ( DISTINCT ( 'Table'[Column1] ), DISTINCT ( 'Table'[Column2] ) )
    ),
    [Column1] <> BLANK ()
        && [Column1] <> ""
)


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello @Naveen_SV 

 

you need to create a new measure, not add a new column

grafik.png
If this post helps or solves your problem, please mark it as solution.
Kudos are nice to - thanks
Have fun

Jimmy

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.

Top Solution Authors