Forum Discussion
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%)
Any help appreciated!
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)
6 Replies
- wdx223_Daniel
Community Champion
Percentage%=DIVIDE([# Classes Canged],[# ALL classes],0)
- Meme123New Member
Sorry, I should have noted that '#Classes changed' and '#All classes' are from two different tables.
- TomasAndersson
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!
- Samarth_18
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) - Meme123New Member
I should have noted that '#Classes changed' and '#All classes' are from two different tables.
- TomasAndersson
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.