Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

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

Adrian

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

     

     

     

     

     

     

     

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

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

  • Hello Anonymous 

    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

    • Anonymous's avatar
      Anonymous
      Not applicable

      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
      • quantumudit's avatar
        quantumudit
        Super User

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