Forum Discussion

Farwest's avatar
Farwest
Frequent Visitor
6 years ago
Solved

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

  • Anonymous's avatar
    Anonymous
    6 years ago

    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 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 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 visual

    Best Regards

    Rena

6 Replies

    • Farwest's avatar
      Farwest
      Frequent Visitor

      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)

       

       

      • amitchandak's avatar
        amitchandak
        Super User

        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])
        )

  • Anonymous's avatar
    Anonymous
    Not applicable

    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 ?