Forum Discussion
Divide one column by another in a matrix
- 9 years ago
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
- 9 years ago
Add index column to your data model and then user that column for count.
step 1: click edit query
step 2 : add index column
and this is how it will show in your data model, you can change the header label whatever you want
and change all formulas from sum to count like this:
Unused Total= CALCULATE(COUNT(Table[Index]),FILTER(Table,Table[Usage Status]="Unused"))
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.
- parry2k9 years ago
Super User
Add index column to your data model and then user that column for count.
step 1: click edit query
step 2 : add index column
and this is how it will show in your data model, you can change the header label whatever you want
and change all formulas from sum to count like this:
Unused Total= CALCULATE(COUNT(Table[Index]),FILTER(Table,Table[Usage Status]="Unused"))
- cwoy2j9 years agoRegular Visitor
Thanks to both of you!