Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Grouping calculated measures as values in a matrix

Hi,

 

I current have a table as follows;

 

 Category ACategory BCategory CCategory D
Value 11111
Value 21111
Value 31111
Value 41111
Value 51111
Value 61111

 

Each of the values in the above table is based on a calculated measure.  My problem that I am facing is that I would liek to group values, in order to expand and minise rows based on grouping of the values.  For example;

 

  Category ACategory BCategory CCategory D
Group 1     
 Value 11111
 Value 21111
Group 2     
 Value 31111
 Value 41111
Group 3     
 Value 51111
 Value 61111

 

I appreciate that the matric has a +/- function in the formatting for rows, but given that my values are based off calculated measures, I don't have this functionality.  A way around this would be perfect, so all help is much appreciated!

 

Thannks

  • Hi Anonymous ,

     

    Create a table with the following format:

    Measure    Group

    Value 1 Group 1
    Value 2 Group 1
    Value 3 Group 2
    Value 4 Group 2
    Value 5 Group 3
    Value 6 Group 3

     

    Now add the following measure:

    Grouping Calculation = 
    VAR Group_calculation =
        SWITCH (
            SELECTEDVALUE ( 'Grouping_Measures'[Group] );
            "Group 1"; [Value 1] + [Value 2];
            "Group 2"; [Value 3] + [Value 4];
            "Group 3"; [Value 5] + [Value 6]
        )
    RETURN
        SWITCH (
            SELECTEDVALUE ( 'Grouping_Measures'[Measure] );
            "Value 1"; [Value 1];
            "Value 2"; [Value 2];
            "Value 3"; [Value 3];
            "Value 4"; [Value 4];
            "Value 5"; [Value 5];
            "Value 6"; [Value 6];
            Group_calculation
        )
    

     

    Format your matrix with the following way:

    • Rows:
      • Grouping_Measures[Group]
      • Grouping_Measures[Measure]
    • Columns
      • Table[Category]
    • Values
      • [Groupin Calculation]

     

    See attach result.

     

     

15 Replies

  • Hi Anonymous ,

     

    Create a table with the following format:

    Measure    Group

    Value 1 Group 1
    Value 2 Group 1
    Value 3 Group 2
    Value 4 Group 2
    Value 5 Group 3
    Value 6 Group 3

     

    Now add the following measure:

    Grouping Calculation = 
    VAR Group_calculation =
        SWITCH (
            SELECTEDVALUE ( 'Grouping_Measures'[Group] );
            "Group 1"; [Value 1] + [Value 2];
            "Group 2"; [Value 3] + [Value 4];
            "Group 3"; [Value 5] + [Value 6]
        )
    RETURN
        SWITCH (
            SELECTEDVALUE ( 'Grouping_Measures'[Measure] );
            "Value 1"; [Value 1];
            "Value 2"; [Value 2];
            "Value 3"; [Value 3];
            "Value 4"; [Value 4];
            "Value 5"; [Value 5];
            "Value 6"; [Value 6];
            Group_calculation
        )
    

     

    Format your matrix with the following way:

    • Rows:
      • Grouping_Measures[Group]
      • Grouping_Measures[Measure]
    • Columns
      • Table[Category]
    • Values
      • [Groupin Calculation]

     

    See attach result.

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for the quick reply.  Is it possible to complete the first step given that the values are the results of calculated measures I have created?

       

      Thanks

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

        Hi Anonymous ,

         

        The values that I have created in my file are several measures named Value 1, ..., Value 6. I assumed that what you mean by calculated measures right?

         

        Can you please explain what you mean by complet the first step?

         

        Regards,

        MFelix

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, me again!

       

      Firstly, thanks very much for your help with the solution to my problem.  I have an additional step to this that I need some help with...

       

      I have successfully created the groups within the table, and now would like to conditionally format some fo the values in the groups based on the results.  The problem I have is that because I'm using just the one measure, based on the above, I can't conditionallly format any of the individual rows using the conditional formatting section of the format tab.  I'm guessing I going to have to add some additional DAX to the existing grouping measure, or possibly amend the original measure that the grouping DAX references?

       

      Any idea how I could get aroudn this.

       

      Hope this makes sense.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello, thanks for the solution!
      My measures are different types and want to format some of them as a whole number and some of them as a percentage. Is it possible? I tried to do it in your sample file but can't get the results.

      Thanks in advance!

      • Anonymous's avatar
        Anonymous
        Not applicable

        I've found the solution, maybe someone else needs it. So in measures the function FORMAT(measure, "Percent") works fine. Any measure can have own format in this way.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    As far as i know, Matrix visual is the most common way to expand and collapse rows by groups but measure can only be add to Values field of matrix visual. So there are two ways I can think of.

    The first way is using Calculated Column to get the values instead of Measure.

    The second way is creating a Calculated Table based on the measure and table.

    As i don't know the formula of your Measure, so i did a simple example about the second way.

     

    Best Regards,

    Jay

    Community Support Team _ Jay Wang

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