Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ancamar
Frequent Visitor

Percentajes in a matrix

Hello everyone.

I'm new to using Power BI and I'm hitting a wall with a problem that I can't seem to solve.

I have a dataset with the columns 'limits' (contracted limit) and 'current consumption' with more info like type of consumption and so on.  

Company

Type

Limit

Consumed

A

Advance

100

80

A

Simple

20

0

A

SMS

20

0

B

Advance

100

90

B

Simple

100

50

 

My idea is to complete the data with the percentage consumed using this DAX formula: Cons_porc = data[current_cons]/data[limit]

 

Company

Type

Limit

Consumed

Cons_porc

A

Advance

100

80

0.8

A

Simple

20

0

0

A

SMS

20

0

0

B

Advance

100

90

0.9

B

Simple

100

50

0.5

 


The problem arises when I attempt to build a matrix like this:

ancamar_0-1708619456603.png

 

All individual types of consumption are being calculated correctly, but the top one (general) is simply summing up the individual values and not performing the calculation of 191 divided by 2206.

My configuration is (but i tried to change but doesnt work)

ancamar_1-1708619621818.png

 

Any ideas?

1 ACCEPTED SOLUTION
Bipin-Lala
Super User
Super User

Hi @ancamar ,

 

It seems like you have created a calculated column for calculating the percentages. Since calculated columns work on row context (current row), hence you are getting correct percentages for each row, but incorrect values at sub-total levels. It is simply summing up the percentage values in each row.

 

You can solve this problem by creating a calculated measure instead.

For example - the following shows the sample dataset I created (based on your data)

BipinLala_0-1708621072933.png

The below matrix visual compares the output of consumption percentage calculated via calculated column and measure. You will get the results you were looking for in the field Consumption Percentage Measure.

BipinLala_2-1708621214868.png

The measure created is as follows - 

Consumption Percentage Measure = CALCULATE(SUM('Table'[Consumed])/SUM('Table'[Limit]))

CALCULATE function helps with filter context. For each individual row, we are getting the correct percentage. At the level of Company sub-total, the values are summed up and then the percentage is calculated, as per the formula.

 

You can understand the difference between the outputs of using calculated columns and measures by seeing them side-by-side as shown in the matrix above.

I hope it's the output you were looking for!




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

Proud to be a Super User!


Regards,

Bipin Lala | Business Intelligence Developer



View solution in original post

2 REPLIES 2
Bipin-Lala
Super User
Super User

Hi @ancamar ,

 

It seems like you have created a calculated column for calculating the percentages. Since calculated columns work on row context (current row), hence you are getting correct percentages for each row, but incorrect values at sub-total levels. It is simply summing up the percentage values in each row.

 

You can solve this problem by creating a calculated measure instead.

For example - the following shows the sample dataset I created (based on your data)

BipinLala_0-1708621072933.png

The below matrix visual compares the output of consumption percentage calculated via calculated column and measure. You will get the results you were looking for in the field Consumption Percentage Measure.

BipinLala_2-1708621214868.png

The measure created is as follows - 

Consumption Percentage Measure = CALCULATE(SUM('Table'[Consumed])/SUM('Table'[Limit]))

CALCULATE function helps with filter context. For each individual row, we are getting the correct percentage. At the level of Company sub-total, the values are summed up and then the percentage is calculated, as per the formula.

 

You can understand the difference between the outputs of using calculated columns and measures by seeing them side-by-side as shown in the matrix above.

I hope it's the output you were looking for!




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

Proud to be a Super User!


Regards,

Bipin Lala | Business Intelligence Developer



Wow, that worked flawlessly! It was as simple as that. You saved me!

Thank you very much!

Have a nice weekend!!!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.