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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Raul
Post Patron
Post Patron

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.

1 ACCEPTED SOLUTION
waltheed
Solution Supplier
Solution Supplier

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
ITsmart BI and Analytics consultant

View solution in original post

4 REPLIES 4
waltheed
Solution Supplier
Solution Supplier

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
ITsmart BI and Analytics consultant

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.

 

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.

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.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.