cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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

1 ACCEPTED SOLUTION
MFelix
Super User III
Super User III

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.

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

11 REPLIES 11
v-jayw-msft
Community Support
Community Support

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.

1.PNG

2.PNG

3.PNG

 

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.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
MFelix
Super User III
Super User III

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.

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

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

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


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi,

 

I'm still having some issues with this one.  Below shows what my table actually looks like;

 

Please note the following;

 

  • The calculated measures are the values on the left.  All of these a made up from multiple data sources that are linked togetehr with relationships. 
  • The column headers are from a column within my dataset.  Therefore not calculated measures.
  • Ideally, what I would love to do is have the ability to maximise/minimise the rows based on groups that the calculated measures in the first column fit into.  For example, the 1st 3 rows could be Group 1, rows 4-6 could be group 2 etc.

 

Hi @Anonymous,

Have you tried the option that I gave you?

Can ypu share a sample file?

Regards,
MFelix

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi, thanks for getting back to me.  Unfortunately I can't open your sample attachment as it's a using a newer version than what I currently have installed.  The problem I have is that it a whole rigmarole to get our IT department to update the version I have 😞

 

My question though is, with regards to step one and creating the table, is this a standard table made from scratch, (enter data) or is this built using the values i currently have?

 

PS.  How do I add a sample to the reply?

Hi @Anonymous ,

 

It's a simple table made by inputing the information, but you can make it in an excel spreadsheet or similar.

 

You can add the sample by using a onedrive, googledrive, dropbox or we transfer similar links.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi,

 

My apologies for not being very clear.  The groupings are what I hope to create using the calculated measures that I currently have as measures.  For example, Grouping values 1 & 2 into Group 1, so that I can use the groupings as rows.  Hope this makes sense.

 

Thanks

Hi @Anonymous ,

 

You need to follow what I refer creating a table with the grouping and the name of the measures and then using a switch function for making the calculation within the matrix.

 

Have you checked out the PBIX file I have attached to the post?


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

Top Solution Authors
Top Kudoed Authors