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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Meme123
New Member

Adding in a calculated column - percentage

Hello, 

I'm fairly new to PowerBi and struggling with adding in calculated columns. I need to add a column (in the value field in this matrix table) that claculates the percentage of '#classes changes' against '#all classes'. So the first row should equal 2.36% (462 classes changed out of a total of 19521 classes is 2.36%)

 

Meme123_1-1675308516775.png


Any help appreciated! 

 

 

1 ACCEPTED SOLUTION
Samarth_18
Community Champion
Community Champion

Hi @Meme123 ,

 

You could create a measure as below and format it as percentage:-

Percentage_classes = DIVIDE(sum('table1'[# Classes Changed]),Sum('table2'[# ALL classes]),0)

Samarth_18_0-1675316143039.png

 

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

6 REPLIES 6
Samarth_18
Community Champion
Community Champion

Hi @Meme123 ,

 

You could create a measure as below and format it as percentage:-

Percentage_classes = DIVIDE(sum('table1'[# Classes Changed]),Sum('table2'[# ALL classes]),0)

Samarth_18_0-1675316143039.png

 

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

TomasAndersson
Solution Sage
Solution Sage

Another easy way, if you don't need it to be a calculated column and are ok with a measure (that can be shown as a column in a matrix) could just be to calculate the sum for each and then divide them:

Percentage :=
DIVIDE(
    SUM([# Classes Changed]),
    SUM([# All Classes])
)

It might depend on how your data is structured, but a possiblity.

TomasAndersson
Solution Sage
Solution Sage

Hi!
If # Classes Changed and # All Classes are from different tables you can use LOOKUPVALUE() first.

 

You need some sort of common key for each class in your tables (called ClassKey below, change accordingly). This also assumes that you create the columns in your table with the All Classes (ACTable) value and not the table with Classes Changed (CC Table). You can do it the other way around, but need to switch up the DAX then.

 

Then a calculated column should be able to look something like this:

% changed =
VAR __CurrentClass = 
ACTable[ClassKey]

VAR __ClassesChanged = 
LOOKUPVALUE(CCTable['# Classes Changed'],CCTable[ClassKey], __CurrentClass)
VAR _

return

DIVIDE(
    __ClassesChanged,
    ACTable['# All Classes'])

Good luck!

 

Meme123
New Member

I should have noted that '#Classes changed' and '#All classes' are from two different tables. 

wdx223_Daniel
Super User
Super User

Percentage%=DIVIDE([# Classes Canged],[# ALL classes],0)

Sorry, I should have noted that '#Classes changed' and '#All classes' are from two different tables. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.