Reply
Member
Posts: 108
Registered: ‎02-29-2016
Accepted Solution

How calculate for a total in a measure

Hello community,

I need your help for this situation. I have a table where I need to calculate with a measure the distribution of a total like this:

 

 HoursCostAmountDistribute
CLIENT 1                    5,25                       417,50       1.118,90   
       AREA1                    1,50                       105,00                         701,90   
      AREA 2                    1,25                         62,50                    -     
      AREA 3                    2,50                       250,00                         417,00   
Total                   5,25                       417,50       1.118,90   

 

The measure have had this formula: Distribute = (Cost * TotalAmount) / TotalCost, for exemeple, in the AREA 1 row, the result would be: (105 * 1,118,90) / 417,50 = 281,40.

 

I tried this formula:

Distribute =

  Var 

     TotalAMOUNT = CALCULATE(SUM(Table[Amount]);ALLSELECTED(Client[Client]))

     TotalCOST = CALCULATE(SUM(Table[Cost]);ALLSELECTED(Client[Client]))

  RETURN

     (Table[Cost] * TotalAMOUNT) / TotalCOST 

 

What is the measure formula?

Thank you.


Accepted Solutions
Highlighted
Advisor
Posts: 120
Registered: ‎11-10-2015

Re: How calculate for a total in a measure

Hi Raul, 

 

This should to the trick:

 

client total cost = calculate(sum(Table1[cost]), ALL(Table1[area]))

client total amount = calculate(sum(Table1[amount]), ALL(Table1[area]))

distribute = (sum([cost])/[client total cost]) * [client total amount]

 

 

 

Capture.PNG

Cheers, Edgar Walther
Power BI User Group Netherlands

View solution in original post


All Replies
Highlighted
Advisor
Posts: 120
Registered: ‎11-10-2015

Re: How calculate for a total in a measure

Hi Raul, 

 

This should to the trick:

 

client total cost = calculate(sum(Table1[cost]), ALL(Table1[area]))

client total amount = calculate(sum(Table1[amount]), ALL(Table1[area]))

distribute = (sum([cost])/[client total cost]) * [client total amount]

 

 

 

Capture.PNG

Cheers, Edgar Walther
Power BI User Group Netherlands
Member
Posts: 108
Registered: ‎02-29-2016

Re: How calculate for a total in a measure

Hello @waltheed,

Thanks for your answer but in my case it is not correct. The Area column is in another table (Table2) related to Table1. When I apply your formula, the result it gives me is this:

 CostClient Total Cost
Client 1         417,50                    417,50  
     Area 1         105,00                    105,00  
    Area 2           62,50                      62,50  
    Area 3         250,00                    250,00  
Total         417,50                    417,50  

 

Client Total Cost = CALCULATE(SUM(Table1[Cost]);ALL(Table2[Area]))

 

And the same with Client Total Amount. What was wrong?

Thank you.

Community Support Team
Posts: 2,909
Registered: ‎02-06-2018

Re: How calculate for a total in a measure

[ Edited ]

Hi @Raul,

 

If it is convenient, could you share a dummy pbix file which can reproduce the scenario and your expected output, so that we can help further investigate on it? You can upload it to OneDrive or Dropbox and post the link here. Do mask sensitive data before uploading.)

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Member
Posts: 108
Registered: ‎02-29-2016

Re: How calculate for a total in a measure

Hello @waltheed,

I found the solution with your help. Only change the table in the ALLSELECTED function and I have the correct result.

Thank you for your answer.