cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Frequent Visitor

## Ratio Calculation

I need to calculate a ratio. I have a table with one column for the amount.
There is a column that holds the ClientID and another column that holds the Sub Account for those ClientID.
A ClientID may have more than one SubAccount.
I need to calculate the ratio held in each Sub Account for ClientIDs.
I have my dimension table set up with unique Sub Accounts and corresponding ClientIDs.
How should I arrange my table so I an achieve calculating the ratio? What should my DAX look like?
This is what I have so far for my DAX...
TotalAmountPerClient = CALCULATE(SUM('MainTable'[Amount]), ALLEXCEPT(AccoutNumber, AccountNumber[ClientID]))
TotalAmountPerSubaccount = SUM('MainTable'[Amount])

Ratio = DIVIDE([TotalAmountPerClient] , [TotalAmountPerSubaccount])

Any help appreciated

1 ACCEPTED SOLUTION
Continued Contributor

You don't need a data model for this but, if you have a model, still this formula will work. Here is the DAX measure that you can use:

``````Ratio =
VAR _clientTotal =
CALCULATE (
SUM ( MainTable[Amount] ),
FILTER (
ALL ( MainTable ),
MainTable[ClientID] = SELECTEDVALUE ( MainTable[ClientID] )
)
)
VAR _ratio =
DIVIDE ( SUM ( MainTable[Amount] ), _clientTotal )
RETURN
_ratio``````

Well instead of  SUM ( MainTable[Amount] ) you can create a simple measure like this and use it too:

``Total Amount = SUM ( MainTable[Amount] )``

Here is the screenshot of the solution:

Hope this will resolve your issue.

Best Regards,
Udit

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍

🚀 Let's Connect: LinkedIn || YouTube || Medium || GitHub

5 REPLIES 5
Frequent Visitor

@quantumudit
Bravo!
That was perfect, it worked.
Thanks for taking the time to look and provide the solution.

Continued Contributor

Happy to help 😊

Best Regards,
Udit

🚀Let's Connect: LinkedIn || YouTube || Medium || GitHub

Continued Contributor

It would be great if you could provide more clarity on this problem. What do you mean by "I have a table with one column for the amount"? Does this table have both "ClientID" and "SubAccount" columns as well? The reason behind asking this question is, that we need to the amount is present at the "ClientID" level or, at the "SubAccount" level.

Even better would be, if you provide a sample dataset (anonymized) along with a screenshot/data of the expected answer. That will help us understand the granularity of the data and thereby form the appropriate solution.

Best Regards,
Udit

🚀 Let's Connect: LinkedIn || YouTube || Medium || GitHub

Frequent Visitor

Thanks for taking a look and the question.
Yes the MainTable does hold all three columns. ClientID, SubAccount and Amount. Here's a sample of the data.

 ClientID SubAccount Amount 231RQ1 231RQ2B1 17785 231YHP 231YHET2 185966.1 231YHP 231YHET3 132062
Continued Contributor

You don't need a data model for this but, if you have a model, still this formula will work. Here is the DAX measure that you can use:

``````Ratio =
VAR _clientTotal =
CALCULATE (
SUM ( MainTable[Amount] ),
FILTER (
ALL ( MainTable ),
MainTable[ClientID] = SELECTEDVALUE ( MainTable[ClientID] )
)
)
VAR _ratio =
DIVIDE ( SUM ( MainTable[Amount] ), _clientTotal )
RETURN
_ratio``````

Well instead of  SUM ( MainTable[Amount] ) you can create a simple measure like this and use it too:

``Total Amount = SUM ( MainTable[Amount] )``

Here is the screenshot of the solution:

Hope this will resolve your issue.

Best Regards,
Udit

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍

🚀 Let's Connect: LinkedIn || YouTube || Medium || GitHub

Announcements

#### Fabric certifications survey

Certification feedback opportunity for the community.

#### Power BI Monthly Update - April 2024

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

#### Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors