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
Js112233
Helper I
Helper I

Sum of values that have been duplicated

Hello there! 

 

I have an odd problem that I can't seem to wrap my mind around. I have a table formatted like this:

 

IDEmployeeHoursCause MaterialsMaterial Hours
F544.070Employee 11Fire Truck 11
F544.070Employee 11Fire Truck 21
F544.070Employee 22Fire Truck 31
F544.070Employee 22Fire Truck 41
F544.070Employee 31Fire Truck 51
F544.070Employee 31Fire Truck 61
F544.070Employee 42Fire Truck 71
F544.070Employee 42Fire Truck 81
F544.070Employee 53Fire Truck 91
F544.070Employee 51Fire Truck 101
F544.070Employee 61Fire Truck 111
F544.070Employee 61Fire Truck 121

 

This report is used to track employees, hours spent on the job, what job they responded to, and the materials used on the job. Unfortunately there are ALWAYS more materials corresponding to a jon (ID) number so it formats like the about, i.e. creating more information.  It can be duplicates, triplicates, etc etc depending on how many materials are used on the job.

 

So when I want to sum the hours for the employee on a particular job it is not correct. Is there a way to get a distinct sum based off of the ID number?

15 REPLIES 15
Phil_Seamark
Employee
Employee

Hi there,

 

Can you please provide some more info.  I take it you've tried a simple SUM(table[Material Hours]) and this is giving you a number higher than expected?  From your screenshot this might produce a value of 12 for the job with the ID of F544.070 ?

 

What number should be shown in this case?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

It should show 12 for the materials however the employee hours are not accurate. For example there should only be entry per employee for an ID, so Employee 1 should have a sum of 1 hour on the job. Instead, Employee 1 has two.

Is there anyway you can post a copy of a cut down PBIX file here?  

 

It might be good to understand the tables and how they relate to better answer your question.

 

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hey there, thanks for taking the time to reply. Here is a quick copy paste of what the table looks like:

 

IDMaterialNumber_of_MaterialsCostEmployeeHours
F123.44Pipe7$1Employee 17
F123.44Rock2$1Employee 17
F123.44Sand2$1Employee 17
F123.44Dump Truck3$1Employee 17
F123.44Compressor1$1Employee 17
F123.44Truck21$1Employee 17
F123.44Excavator1$1Employee 17
F123.44Truck31$1Employee 17
F123.44Truck41$1Employee 17
F123.44Concrete24$1Employee 17
F123.44Dirt5$1Employee 17
F123.44Lane Fee1$1Employee 17
F123.44Rock27$1Employee 27
F123.44Pipe2$1Employee 27
F123.44Rock2$1Employee 27
F123.44Sand3$1Employee 27
F123.44Dump Truck1$1Employee 27
F123.44Compressor1$1Employee 27
F123.44Truck21$1Employee 27
F123.44Excavator1$1Employee 27
F123.44Truck31$1Employee 27
F123.44Truck424$1Employee 27
F123.44Concrete5$1Employee 27
F123.44Dirt1$1Employee 27
F123.44Lane Fee7$1Employee 37
F123.44Rock22$1Employee 37
F123.44Pipe2$1Employee 37
F123.44Rock3$1Employee 37
F123.44Sand1$1Employee 37
F123.44Dump Truck1$1Employee 37
F123.44Compressor1$1Employee 37
F123.44Truck21$1Employee 37
F123.44Excavator1$1Employee 37
F123.44Truck324$1Employee 37
F123.44Truck45$1Employee 37
F123.44Concrete1$1Employee 37

 

So going to the employee column you can see that employee 1 looks to have worked many more hours than he actually did. The employee only gets one entry per unique job ID. The materials column has so much more in it that it pushes everything down with it. Employees 1, 2 & 3 all only worked 7 hours on the job.

You could create a new Table using DAX that summarises the data down to 1 line per employee/job using this

 

Employee Job Hours = SUMMARIZECOLUMNS('Table'[ID],'Table'[Employee],"Hours",MAX('Table'[Hours]))

 

Does that help?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

This would have to be a new table rather than a measure within the existing?

This measure could be added to your table that contains the duplicate hours and return the single value for each employee

 

MyMeasure = CALCULATE(MAX('Table'[Hours]),ALLEXCEPT('Table','Table'[Employee]))

 

Might need to add job in there but would need more data/info to be sure.


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hey I think we are on to something with this! If I were to add the job ID in there where would it go?

 

 

I am a total newbie, thanks for bearing with me.

MyMeasure = CALCULATE(MAX('Table'[Hours]),ALLEXCEPT('Table','Table'[Employee],'Table'[ID]))


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Well, when I create a new table with your first suggestion the values are correct! However, with this latest one it is not returning the correct sum.

Can you post a screenshot of what it is showing and let me know what it should be?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

It is not summing correctly. It will have the correct hours but in the total the number will be wrong. For example have correct hours for seven jobs that show one hour each. Total should say 7 but says 13 instead.

Bumping to see if anyone has any other ideas

Hey there, I am still thinking about this.  

 

Is there anyway you can share a copy of your PBIX file (or stripped version of it) and I'm sure I can resolve for you.

 

Phil


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Let me try to throw something together that I can share, it is a large file with a TON of other information within. 

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.