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

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

Reply
adrianlochan
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])
adrianlochan_0-1712940685767.png

Any help appreciated

Adrian

1 ACCEPTED SOLUTION

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:

quantumudit_0-1712947256857.png

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
Visit My Linktree: LinkTree

 

 

 

 

 

 

 

View solution in original post

5 REPLIES 5
adrianlochan
Frequent Visitor

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

Happy to help 😊

 

Best Regards,
Udit


🚀Let's Connect: LinkedIn || YouTube || Medium || GitHub
Visit My Linktree: LinkTree

quantumudit
Continued Contributor
Continued Contributor

Hello @adrianlochan 

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
Visit My Linktree: LinkTree

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.

ClientIDSubAccountAmount
231RQ1231RQ2B117785
231YHP231YHET2185966.1
231YHP231YHET3132062

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:

quantumudit_0-1712947256857.png

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
Visit My Linktree: LinkTree

 

 

 

 

 

 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors