Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 years ago
Solved

Slicer by columns name

Hello,

 

I have the following table:

 

 

Sale_IDUnity_PriceTax_1Tax_2Tax_3Tax_4
11051584
240302587


To calculate the final price of a sale I created a calcualted column with the following formula:

 

Final_Price = Unity_Price + Tax_1 + Tex_2 - Tax_3 - Tax_4

 

Now I want to filter the final price by my columns names:

 

Slicer -- 

Unity_PriceTax_1Tax_2Tax_3Tax_4

 

Table Visual --

Sale_IDFinal_Price
118
280

 

If I click on Unity_Price the it must shows this:

 

Slicer -- 

Unity_PriceTax_1Tax_2Tax_3Tax_4

 

Sale_IDFinal_Price
110
240

 

Or if I multiselect items, all taxes for example, it must shows this:

 

Slicer -- 

Unity_PriceTax_1Tax_2Tax_3Tax_4

 

Sale_IDFinal_Price
18
240

 

 

How can I do that?

Thanks.

  • Hi Anonymous,

     

    I would solve this using a measure do the following:

    1. Create a table (do not related this with any other tables with the following structure:
      1. Name Slicer - Selection: Unity_Price, Tax_1, Tax_2, Tax_3, Tax_4
    2. Add the following measure to your data table:
    3. Final_Price =
      VAR Unity_price =
          IF (
              CONTAINS ( Slicer, Slicer[Selection], "Unity_Price" ) = TRUE (),
              SUM ( Sales[Unity_Price] ),
              0
          )
      VAR Tax1 =
          IF (
              CONTAINS ( Slicer, Slicer[Selection], "Tax_1" ) = TRUE (),
              SUM ( Sales[Tax_1] ),
              0
          )
      VAR Tax2 =
          IF (
              CONTAINS ( Slicer, Slicer[Selection], "Tax_2" ) = TRUE (),
              SUM ( Sales[Tax_2] ),
              0
          )
      VAR Tax3 =
          IF (
              CONTAINS ( Slicer, Slicer[Selection], "Tax_3" ) = TRUE (),
              SUM ( Sales[Tax_3] ),
              0
          )
      VAR Tax4 =
          IF (
              CONTAINS ( Slicer, Slicer[Selection], "Tax_4" ) = TRUE (),
              SUM ( Sales[Tax_4] ),
              0
          )
      RETURN
          Unity_price + Tax1
              + Tax2
              - Tax3
              - Tax4
    4. Now just add the valuies from the table you created to a slicer and your measure to the table should give the expected result:

     

    Regards,

    MFelix

32 Replies

  • Hi Anonymous,

     

    I would solve this using a measure do the following:

    1. Create a table (do not related this with any other tables with the following structure:
      1. Name Slicer - Selection: Unity_Price, Tax_1, Tax_2, Tax_3, Tax_4
    2. Add the following measure to your data table:
    3. Final_Price =
      VAR Unity_price =
          IF (
              CONTAINS ( Slicer, Slicer[Selection], "Unity_Price" ) = TRUE (),
              SUM ( Sales[Unity_Price] ),
              0
          )
      VAR Tax1 =
          IF (
              CONTAINS ( Slicer, Slicer[Selection], "Tax_1" ) = TRUE (),
              SUM ( Sales[Tax_1] ),
              0
          )
      VAR Tax2 =
          IF (
              CONTAINS ( Slicer, Slicer[Selection], "Tax_2" ) = TRUE (),
              SUM ( Sales[Tax_2] ),
              0
          )
      VAR Tax3 =
          IF (
              CONTAINS ( Slicer, Slicer[Selection], "Tax_3" ) = TRUE (),
              SUM ( Sales[Tax_3] ),
              0
          )
      VAR Tax4 =
          IF (
              CONTAINS ( Slicer, Slicer[Selection], "Tax_4" ) = TRUE (),
              SUM ( Sales[Tax_4] ),
              0
          )
      RETURN
          Unity_price + Tax1
              + Tax2
              - Tax3
              - Tax4
    4. Now just add the valuies from the table you created to a slicer and your measure to the table should give the expected result:

     

    Regards,

    MFelix

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you, MFelix, it solved my problem.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hey Meflix,

       

      I've almost similar issue but I'm not able to resolve it the way you mentioned.

      Following are the steps

      • Slicer with four different column names
      • Select a column name
      • Divide the values in column with values in another column present in data
      • Use this measure on the graph

      I tried following the code you mentioned but instead of Sum(Sales[VAR]) I want Divide(VAR, Column Name)

      The code is returning a lot of errors

       

      ETA_Quality =
      VAR On_Time =
      IF (
      CONTAINS ( Slicer, Slicer[V_Selection], "On Time" ) = TRUE (),
      Divide( 'Volvo ETA'[On-Time], 'Volvo ETA'[Total], Blank()),
      0
      )
      VAR Early =
      IF (
      CONTAINS ( Slicer, Slicer[V_Selection], "Early" ) = TRUE (),
      Divide( 'Volvo ETA'[Early], 'Volvo ETA'[Total], Blank()),
      0
      )
      VAR Late =
      IF (
      CONTAINS ( Slicer, Slicer[V_Selection], "Late" ) = TRUE (),
      Divide( 'Volvo ETA'[Late], 'Volvo ETA'[Total], Blank()),
      0
      )
      VAR Cancelled =
      IF (
      CONTAINS ( Slicer, Slicer[V_Selection], "Cancelled" ) = TRUE (),
      CALCULATE( 'Volvo ETA'[Cancelled] 'Volvo ETA'[Total], Blank()),
      0
      ) Return Cancelled+Early+Late+On_Time

       

      Also instead of last Return Cancelled+Early+Late+On_Time, I just want to Return all of them which will eventually display the VAR value based on Column Selection.

       

      Thanks!

      • MFelix's avatar
        MFelix
        Icon for Super User rankSuper User

        Hi Anonymous,

         

        When you use measure they are calculated based on context so you cannot make the calculations based on a single value from a colum, meaning that when you have 

        VAR On_Time =
        IF (
        CONTAINS ( Slicer, Slicer[V_Selection], "On Time" ) = TRUE (),
        Divide( 'Volvo ETA'[On-Time], 'Volvo ETA'[Total], Blank()),
        0
        )

        You should have something like this:

         

        VAR On_Time =
        IF (
            CONTAINS ( Slicer, Slicer[V_Selection], "On Time" ) = TRUE (),
            DIVIDE ( SUM ( 'Volvo ETA'[On-Time] ), SUM ( 'Volvo ETA'[Total] ), BLANK () ),
            0
        )

        In this way you are aggregating the values, however be carefull because this can sometimes based on context not return the expected result.

         

        Can you please share some sample data and show the expected result in that way I can adjust the formula better.

         

        Regards,

        MFelix

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi MFelix I have similar issue and i want to create a slicer where column name will be slicer and when i click on slicer it should change the data in teh donut. 

       

      Please see the screenshot below where is have shown my whole data. I am not sure where to upload PBIx file and attaching screeshot here.. Here is the table:

      BadgeIDJob TitleCountryFirstNameLastNameBoothNumberBooth NameDuration Seconds
      123EngineerUSAabcWoods27Booth 1600
      456EngineerGermanydefWoods27Booth 1480
      789EngineerIndiaghiSa27Booth 11320
      532Chief Information OfficerUSAjklVa14Booth 2240
      1182304Operations ManagerUSAChetManchester21Booth 3980
      1182523Account ManagerUSATravisFulton21Booth 31080
      1182657Senior EngineerIndiaLuisaSangines21Booth 31680
      1182879EngineerUSAMarkSkallet21Booth 3480
      1149995AnalystUSAMeganHemmila37Booth 41200
      1149995AnalystIndiaMeganHemmila37Booth 42280
      1150180Architect|PartnerIndiaHoaTram37Booth 41200
      1150180Architect|PartnerGermanyHoaTram37Booth 4480
      117Senior EngineerUSApqrPa14Booth 2360

       

       

      • MFelix's avatar
        MFelix
        Icon for Super User rankSuper User

        Hi Anonymous,

         

        You can do this making  of 3 options

        1. Dynamic Hierarchie
        2. Unpivot Columns
        3. Bookmarks

         

        1. Dynamic Hierarchie

        Using this post I adapted the situation and made the following

         

        • Created a new table with the following code:

         

        Country Job Hierarchy =
        UNION (
            SELECTCOLUMNS (
                'Hierarchy';
                "Badge ID"; 'Hierarchy'[BadgeID];
                "Hierarchy Name"; 'Hierarchy'[Job Title];
                "Level"; "Job Title";
                "LevelNumber"; 1
            );
            SELECTCOLUMNS (
                'Hierarchy';
                "Badge ID"; 'Hierarchy'[BadgeID];
                "Hierarchy Name"; 'Hierarchy'[Country];
                "Level"; "Country";
                "LevelNumber"; 2
            )
        )

        j

         

        • Make a relationship between this table and your main table by BadgeID: be aware that this will create a many to many relationship. If you don't have the latest version of PBI you need to make a dimension table for Uniques BadgeID and then relate this with the two other table
        • Make this relationship with a cross filter in both directions
        • Add the Column Hierarchy name to your legend and the count of what ever field you want from the main table.

         

             2. Unpivot Column (link to unpivot columns)

         

        • Query Editor Select both country and Job title column
        • Transform Unpivot
        • Get 2 columns atribute and value
        • Add Attribute to slicer and  value to legend in chart

         

         

            3. Bookmarks (link to bookmarks documentation)

         

        • Create two buttons Job title Country
        • Create two donut charts one with job title and the cother with country on legend
        • Hide the Job Title chart and create the bookmark named country and make it an action of the Country button and vice-versa
        • Then just click on the buttons (on desktop version you have to use CTRL + CLICK)

         

        See below the screenshot and the PBIX file with all the options above.

         

         

        Regards,

        MFelix

         

  • neenae2860's avatar
    neenae2860
    Frequent Visitor

    MFelix  Could you please help I wanted to create slicer from column name. Please see my data table.

    IdAgeBoyGirlAdultChild
    125TRUEFALSETRUEFALSE
    230FALSETRUETRUEFALSE
    312TRUEFALSEFALSETRUE

    This is my data table. I wanted to create slicer which have Boy,Girl,Adult and Child as filter.

    Consider to show only true condition and ignore false condition.

     

    For example once I select Boy. This should show up.

    IdAgeBoyGirlAdultChild
    125TRUEFALSETRUEFALSE
    312TRUEFALSEFALSETRUE

     

     

     Another example: If I select Adult this should show up.

    IdAgeBoyGirlAdultChild
    125TRUEFALSETRUEFALSE
    230FALSETRUETRUEFALSE

    Could you please help?

     

    Thank you

    • MFelix's avatar
      MFelix
      Icon for Super User rankSuper User

      hI neenae2860 ,

       

      Create a new table with the values you want to filter:

      I call this table Slicer.

      Now add the following measure:

      Filter measure = SWITCH(SELECTEDVALUE(Slicer[Cat]),
                          "Adult", COUNTROWS(FILTER('Table', 'Table'[Adult] = TRUE())),
                          "Boy", COUNTROWS(FILTER('Table', 'Table'[Boy] = TRUE())),
                          "Girl", COUNTROWS(FILTER('Table', 'Table'[Girl] = TRUE())),
                          "Child", COUNTROWS(FILTER('Table', 'Table'[Child] = TRUE()))
                          )

      Add this measure has a filter on the visualization you need and set it to is not blank.

       

       

       

  • Hi MFelix ,

    I want to create a slicer of multiple columns based on another slicer having parameters.

    for example raw data is like this:

    EventStudent IDMaths teacherScience TeacherEnglish Teacher
    Exhibition1Ravi ChandraSpriha DasVandana p
    Exhibition2RK Das Mamta Chobey
    Exhibition3 Rajesh RanjanRajesh Ranjan

     

    So first slicer should have values like Maths, Science and English:

    Slicer 1
    Maths
    Science
    English

     

    And second slicer should filter based on Slicer 1 for example if Maths is selected in slicer 1 , then slicer 2 should have following values:

    Slicer 2
    Ravi Chandra
    RK Das

     And table should show this:

    EventStudent IDMaths teacher
    Exhibition1Ravi Chandra
    Exhibition2RK Das

     

    I tried with field parameters but it cant be used in report server

    Please help me with this.

  • Anonymous's avatar
    Anonymous
    Not applicable

    MFelix 

     

    I saw your post and wonder if you could help me as well 😁

     

    I am also trying to create a category slicer based on the Column name,  each category(product) has 3 sub-columns, and they are the same product.

    Like, Volumn, MS, Rank, all same 3 columns for each product AAA, BBB, CCC.  

     

    I want to create a slicer to filter on the product name AAA, BBB, CCC, so that each time when the user click on each product, together with other row slicer (like period in this example),  a different table will appear. 

    Thanks in advance!!!

    Customer NamePeriodAAA-VolumnAAA-MSAAA-RankBBB-VolumnBBB-MSBBB-RankCCC-VolumnCCC-MSCCC-Rank
    SmithMonth210%312%242%2
    JohnMonth320%223%323%2
    AlbertMonth430%134%1330%3
    AprilMonth510%345%2223%3
    SmithQTR430%332%115%1
    JohnQTR520%223%3220%3
    AlbertQTR120%111%2334%2
    AprilQTR410%312%445%4
    SmithYTD510%355%222%3
    JohnYTD720%224%1320%1
    AlbertYTD230%135%323%2
    AprilYTD210%313%1110%3

     

    Category Slicer Customer NameAAA-VolumnAAA-MSAAA-Rank
    AAA Smith210%3
    BBB John320%2
    CCC Albert430%1
      April510%3
    Period Slicer     
    Month