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
Farwest
Frequent Visitor

Column selection based on Filter

Dear Power BI community,

 

I am having a hard time setting a dynamic filter on a report.

 

I am trying to use a filter in order to set a measure, it is a single selection filter.

 

Selected = if(HASONEVALUE('Table['Name]);SELECTEDVALUE('Table[Name]);"ALL")

 

I am getting the selected filter through this and using switch to select a column based on the selection

 

SWITCH([Selected];"ALL";MAX(Table[Name1]);MAX(Table[Name2]))

 

I would like to use a column if nothing is selected (Table[Name1]) and the other column (Table[Name2]) for any single selection filter.

 

I tried as well with the following measures

 

Selected = COUNTROWS(FILTERS('Table['Name])) this is to get how many filters are selected in the visual

 

I am then setting this condition using the above measure

IF ([Selected] > 1 ; MAX(Table[Name1]) ; MAX('Table'[Name2]))

 

Both are always returing the same column regardless of the condition.

 

Appreciate your help

1 ACCEPTED SOLUTION

Hi @Farwest ,

Please try to complete the following steps to achieve your requirement:

1. Create one dimension table for name field(Group 1,Group 2,Group 3 etc. )

Create table GroupsCreate table Groups

2. Create the relationship between two tables using field "Group" in Groups table and "Name" field in Table

Create relationship between dimension and fact tableCreate relationship between dimension and fact table

3. Create a measure and drag the related fields onto the visual as below screen shot

Measure = IF(ISFILTERED('Groups'[Group]),MAX('Table'[Name 2]),MAX('Table'[Name 1]))

Create measure and table visualCreate measure and table visual

Best Regards

Rena

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

6 REPLIES 6
pranay2k2
Advocate I
Advocate I

Even i'm having a similar requirement ..

 

Whenver user select single value from slicer in a dynamic table then we should filter out null records but whenever use select more than 1 column then display all values in every columns (no need to filter out.) Any idea how to achieve this ?

amitchandak
Super User
Super User

Thanks @amitchandak 

 

This actually works better, but I still have a problem.

 

IF(HASONEFILTER('Table' [Name]);
SWITCH(SELECTEDVALUE('Table' [Name]);
"Selected"; MAXX('Table' [Name 1]);
MAXX('Table' [Name 2])
);
MAXX('Table' [Name 2])
)

 

This works when I define the selected Filter Value "Selected", but I am trying  to:

if only one filter is selected then get 'Table' [Name 1] otherwise (all selected) get 'Table' [Name 2]  (this is a single filter selection anyway)

 

 

@Farwest ,

Try like


IF(isfiltered('Table' [Name]) && HASONEFILTER('Table' [Name]);
SWITCH(SELECTEDVALUE('Table' [Name]);
"Selected"; MAXX('Table' [Name 1]);
MAXX('Table' [Name 2])
);
MAXX('Table' [Name 2])
)

@amitchandak 

 

Tried out as well but not really reaching the expected result.

I am adding more details to better exlain the case, the result I have today is a bit different.

When no filter is selected group 3 is still showing Name 1 table where it should be Name 2 as per the DAX on previous post.

Every time one group is filtered I would liket o get Table[Name 1]

Every time no filter is selected I would like to get Table [Name 2]

 

I have hundreds of groups so I don't want to enter them one by on in the SWITCH like SWITCH(SELECTEDVALUE('Table' [Name]);
"Group 1"; ...."Group 2";...

 

Capture.JPG

Hi @Farwest ,

Please try to complete the following steps to achieve your requirement:

1. Create one dimension table for name field(Group 1,Group 2,Group 3 etc. )

Create table GroupsCreate table Groups

2. Create the relationship between two tables using field "Group" in Groups table and "Name" field in Table

Create relationship between dimension and fact tableCreate relationship between dimension and fact table

3. Create a measure and drag the related fields onto the visual as below screen shot

Measure = IF(ISFILTERED('Groups'[Group]),MAX('Table'[Name 2]),MAX('Table'[Name 1]))

Create measure and table visualCreate measure and table visual

Best Regards

Rena

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

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.