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
cwoy2j
Regular Visitor

Divide one column by another in a matrix

Hi,

 

I'm creating a couple of matrices in Power BI and I'm trying to create one that has counts by a certain stat and the other will show the percentage. It was easy enough to get the counts (see below). However, I'm having a hard time creating percentages. What I want to do is show the percent of Used or Unused by Fiscal Year by Scholarship Type. So the Unused % for Awareness for FY15 would be 15% and Used would be 85%. How would I go about doing it? I'm fairly new to BI so apologies if this is something simple.

 

 FY15FY16 
Scholarship TypeUnusedUsed TotalUnusedUsed TotalGrand Total
Awareness1910812757461518645
Partner69686755124108112051960
Recognition88554642616166771319
Regulator2028030079382461761

 

Also, here's how the underlying table in the data model is structured

 

Scholarship Recipient IDUsage StatsFiscal YearScholarship Type
4529783UsedFY15Recognition
10564207UsedFY16Recognition
6409092UsedFY16Recognition
30748898UsedFY15Recognition
17522706UsedFY16Recognition
18329306UsedFY16Partner
17310161UsedFY15Recognition
21357211UsedFY16Awareness
2 ACCEPTED SOLUTIONS
v-sihou-msft
Employee
Employee

@cwoy2j

 

In a Matrix, the columns are generated based on column group data fields which is dynamic. We can't directly have one column divide by another column.

 

In your scenario, you need to limit the scope for current row context in your calculations. You can create two measures, one for Unused, the other for Used. Then calculate the percentage based on the those two measures.

 

Unused Total= CALCULATE(SUM(Table[Value]),FILTER(Table,Table[Usage Status]="Unused"))

 

 

Used Total= CALCULATE(SUM(Table[Value]),FILTER(Table,Table[Usage Status]="Used"))

 

 

Used Pct= [Used Total]/([Unused Total]+[Used Total])

 

 

Unused Pct= [Unused Total]/([Unused Total]+[Used Total])

 

 

Regards,

Simon Hou

 

 

 

 

View solution in original post

Add index column to your data model and then user that column for count.

 

step 1: click edit query

step 2 : add index column

index1.PNG

 

and this is how it will show in your data model, you can change the header label whatever you want 

 

Index2.PNG

 

and change all formulas from sum to count like this:

 

 

Unused Total= CALCULATE(COUNT(Table[Index]),FILTER(Table,Table[Usage Status]="Unused"))

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

5 REPLIES 5
v-sihou-msft
Employee
Employee

@cwoy2j

 

In a Matrix, the columns are generated based on column group data fields which is dynamic. We can't directly have one column divide by another column.

 

In your scenario, you need to limit the scope for current row context in your calculations. You can create two measures, one for Unused, the other for Used. Then calculate the percentage based on the those two measures.

 

Unused Total= CALCULATE(SUM(Table[Value]),FILTER(Table,Table[Usage Status]="Unused"))

 

 

Used Total= CALCULATE(SUM(Table[Value]),FILTER(Table,Table[Usage Status]="Used"))

 

 

Used Pct= [Used Total]/([Unused Total]+[Used Total])

 

 

Unused Pct= [Unused Total]/([Unused Total]+[Used Total])

 

 

Regards,

Simon Hou

 

 

 

 

Unfortunately this didn't work. The Usage Stats column in the underlying table is a text field.

 

Error Message: MdxScript(Model) (1, 62) Calculation error in measure 'ScholarshipData'[Unused Total]: The function SUM takes an argument that evaluates to numbers or dates and cannot work with values of type String.

Add index column to your data model and then user that column for count.

 

step 1: click edit query

step 2 : add index column

index1.PNG

 

and this is how it will show in your data model, you can change the header label whatever you want 

 

Index2.PNG

 

and change all formulas from sum to count like this:

 

 

Unused Total= CALCULATE(COUNT(Table[Index]),FILTER(Table,Table[Usage Status]="Unused"))

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thanks to both of you!

Thank you! I will try this out when I get back to work next week. Appreciate the response.

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.