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
JC-80
New Member

Multiply Columns within different Tables - Not giving correct output...

Hi, 

 

I am hoping someone can assist. 

 

I have 2 tables of data Table A has all the data contained within it and Table B has unique fields - the relationship is Many to One.

 

Table A has Columns 'Name', 'Hours Worked', 'Date Logged' and 'Project' 

Table B has Columns 'Name', 'Base Day Rate' and 'Base Hourly Rate' 

 

The calcualtion I want is to show the 'Total Cost per Person' - the calculation I did use to start with was: 

 

Total Cost per Person = SUM('TableA'[Hours_Worked]) * SUM('Table B'[Base_Hourly_Rate]), this was then broken down by individual and date logged (please take into account 1 individual has a number of entries against a single day, as they are allocating time against tasks e.g. Person 1 logs 4 entries for 01/06/2016 equating to a total of 7 hours. Using the calculation, I hoped to see how much each task has cost.)

 

This was showing very weird calculations! As an example, the month of June should have shown a total of £435,653.85 but though Power BI it shows £36,269,076.87!

  

I am new to Power BI and using DAX, so apolgies if I am missing something obvious but any help would be greatly appreciated. 

 

Many thanks Smiley Happy

 

 

 

1 ACCEPTED SOLUTION

In this example I managed to fix the issue. 

 

I completed a merge on the 2 tables with the relevant data. This created a column that contained all of the columns from 'Table 2', so I picked 'Hourly Rates'. I then created a calculated column multiplying the 'Hours' column by the 'Hourly Rates' column, this gave me the desired outcome. 

 

Thanks for everyones suggestions and help. Smiley Wink

 

 

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

I *believe* what you are seeing in the Total row is that the measure is essentially not contextually filtered. So, in the total row, it is summing all of your values for all of your base hourly rates and then multiplying that by a sum of all of your hours worked.

 

Essentially:

 

Instead of: ($125 * 16) + ($150 * 16) = $4,400

 

you are getting:

 

($125 + $150) * (16 + 16) = $8,800

 

Remember, a measure's value is controlled by its context and in the Total row, it is removing all of the context essentially and you are getting a wrong answer as a result.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you for the quick response. 

 

I think I understand what you are suggesting but I am not clear on how I can remedy this issue? Is there an alternative solution to get the right result to show? 

 

I need the total, as I want to be able to show the cost against either the project, month or person. This is vital to the report. 

 

Thanks 

Just to add, I have looked at some of the calculation and they dont even seem to be doing that...

 

 

 Correct Calcualtion  Power BI Calculation
 HoursHourly RateCost  HoursHourly RateCost
 1 £       118.57 £        118.57  1£118.57£118.57
 1 £       118.57 £        118.57  1£118.57£118.57
 2 £       118.57 £        237.14  2£118.57£237.14
 2.5 £       118.57 £        296.43  2.5£118.57£296.43
 0.5 £         62.14 £          31.07  0.5£62.14£31.07
 1 £         62.14 £          62.14  1£62.14£62.14
Total8£598.56£863.92 Total8£180.71£1,445.68

 

It looks as though the calculation (according to Power BI), is taking the total number of hours and multiplying it by the unique values within the hourly rate (£118.57 and £62.14 = £180.71). All I need is the total of the cost (£863.92). 

 

Could this be due to the relationship between the 2 tables? 

Hi @JC-80,

Could you please post the sample data of your two tables and post the expected result here?  Regrading to the above table, you can simply create a measure to summarize the cost by using the formula: Measure = SUMX(Table1,Table1[Hours]*Table1[Hours Rate]).

1.PNG


Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

In this example I managed to fix the issue. 

 

I completed a merge on the 2 tables with the relevant data. This created a column that contained all of the columns from 'Table 2', so I picked 'Hourly Rates'. I then created a calculated column multiplying the 'Hours' column by the 'Hourly Rates' column, this gave me the desired outcome. 

 

Thanks for everyones suggestions and help. Smiley Wink

 

 

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.