Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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])
Any help appreciated
Adrian
Solved! Go to 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:
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
@quantumudit
Bravo!
That was perfect, it worked.
Thanks for taking the time to look and provide the solution.
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.
ClientID | SubAccount | Amount |
231RQ1 | 231RQ2B1 | 17785 |
231YHP | 231YHET2 | 185966.1 |
231YHP | 231YHET3 | 132062 |
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
User | Count |
---|---|
15 | |
13 | |
12 | |
10 | |
10 |
User | Count |
---|---|
19 | |
15 | |
14 | |
11 | |
10 |