Forum Discussion

DanCasSan's avatar
DanCasSan
Icon for Helper V rankHelper V
6 years ago
Solved

Use measure as filter

Hello community!

 

Could someone guide me a little with this case? I am working on a measure as a filter to show a bar comparison, but what happens if I choose more than one option in the filter? I understand that the result could not be in a single measure, since if I choose more than one option, each option should be shown as a bar.

 

Any suggestions or tricks to do more or less what is on the chart? Whereas each option is a bar and you can select 1, 2, 3 or the 4 options.

 

Thank you so much!

 

  • DanCasSan 

     

    Following MFelix  idea of a measure table, if you need multiple selection, you can create a measure for each calculation along the lines of (This example is with my measures):

     

     

     

    Sales 2018 (sel) = 
    VAR calc = CALCULATE(DISTINCTCOUNT('Select Measure'[Selected Measure]);
        FILTER('Select Measure';
        'Select Measure'[Selected Measure]= "Sales 2018"))
        RETURN
        IF(ISBLANK([Countrows Select Measure]); 
            BLANK() ;
                IF(calc= 1; [Sales 2018]; 
                    BLANK()))

     

     

     

     

    Which gets you this:

     

    Attached is the PBIX file:

     

     

6 Replies

  • Check, if this can help

    https://community.powerbi.com/t5/Desktop/Slicer-MTD-QTD-YTD-to-filter-dates-using-the-slicer/td-p/500115

     

    Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
    In case it does not help, please provide additional information and mark me with @

    Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
    Proud to be a Datanaut Connect on Linkedin

  • Hi DanCasSan ,

     

    Create a new table with the name of the measures you need you can add an ID to simplify and order also your data something similar to this

     

    ID Measure
    1 Measure 1
    2 Measure 2
    3 Measure 3
    4 Measure 4

     

    Then add the following measure to your model:

    Selection measure = SWITCH(
    SELECTEDVALUE('Table'[Measure]);
    1 ;[Measure 1];
    2;[Measure 2];
    3;[Measure 3];
    4;[Measure 4])

     

    Now add the column with the  name measures on the legend or axis of your visualization, then place the previous measure on the values.

     

    Create a slicer with the name measure from the table that you created and should work as expected.

     

    Check a PBIX file with an example with 2 measures.

     

    As you can see on the file the visualizations have different levels of information but all show or hide the selectted measures.

    • DanCasSan's avatar
      DanCasSan
      Icon for Helper V rankHelper V

      Hi Miguel, I did what you recommended, but when I select more than one option, no information comes out. I enclose the image for more detail.

       

      Measure =
      SWITCH(
      SELECTEDVALUE(DS_KPI_Unid[ID]),
      1,[Consumo Real Und.],
      2,[Ingreso Real Und.],
      3,SUM(DS_MPSMRP[BDMNG]),
      4,SUM(DS_MPSMRP[GSMNG]))

       

      • PaulDBrown's avatar
        PaulDBrown
        Icon for Community Champion rankCommunity Champion

        DanCasSan 

         

        Following MFelix  idea of a measure table, if you need multiple selection, you can create a measure for each calculation along the lines of (This example is with my measures):

         

         

         

        Sales 2018 (sel) = 
        VAR calc = CALCULATE(DISTINCTCOUNT('Select Measure'[Selected Measure]);
            FILTER('Select Measure';
            'Select Measure'[Selected Measure]= "Sales 2018"))
            RETURN
            IF(ISBLANK([Countrows Select Measure]); 
                BLANK() ;
                    IF(calc= 1; [Sales 2018]; 
                        BLANK()))

         

         

         

         

        Which gets you this:

         

        Attached is the PBIX file: