Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

how to remove duplicates before computing sum

I have a table like the following:

Week KeyWeek LabelEmployee KeyEmployee NameEmployee LocationDay WorkedHours Worked for DayHours Worked for Week
1Week 11John DoeFloridaMonday840
1Week 11John DoeFloridaTuesday840
1Week 11John DoeFloridaWednesday840
1Week 11John DoeFloridaThursday840
1Week 11John DoeFloridaFriday840
1Week 12Jane DoeCaliforniaTuesday530
1Week 12Jane DoeCaliforniaThursday830

 

As you can see, the grain of this table is week + employee + day worked.  I want a measure that returns the distinct [Hours Worked for Week] value per week + employee.  So, for example, for week 1 + employee 1, I expect this measure to return 40 (not 40*5 = 200).  Similarly, for week 1 + employee 2, I expect this measure to return 30 (not 30*2 = 60).  How can I achieve this?  To be sure, as shown in the data, [Hours Worked for Week] is not always the sum of [Hours Worked for Day].  So, adding up the values in [Hours Worked for Day] is an incorrect solution.

  • Anonymous , try like

    sum Hours Worked for Week = sumx(summarize(Table,Table[Employee Key], Table[Week Key], "_1",max(Table[Hours Worked for Week])),[_1])

2 Replies

  • Hi,

    Drag Week label and Employee key to the table visual and write this measure

    =MIN(Data[Hours Worked for Week])

    Hope this helps.

  • Anonymous , try like

    sum Hours Worked for Week = sumx(summarize(Table,Table[Employee Key], Table[Week Key], "_1",max(Table[Hours Worked for Week])),[_1])