Forum Discussion
SUM on Distinct Month
Hi,
I have the following data below. I am trying to calculate the total distinct EmpPeriodHrs per month. So in this case i have 4 distinct payroll end dates for Payroll End Date that fall in the month of October.. I want to have a column or measure that calculates this. My goal is to have a column or measure that shows 160 repeatedly in this example. This could be different for each of my employees aswell (i have another column for employee id)
Thanks
Hi AlexDawson1111 ,
According to your description, I create a sample with two employees.
Here's my solution, create a calculated column.
Column = CALCULATE ( SUM ( 'Table'[Hours] ), FILTER ( 'Table', EOMONTH ( 'Table'[Payroll End Date], 0 ) = EOMONTH ( EARLIER ( 'Table'[Payroll End Date] ), 0 ) && 'Table'[Employee ID] = EARLIER ( 'Table'[Employee ID] ) ) )Result:
If you want to display the result in a visual, a measure can also work:
Measure = CALCULATE ( SUM ( 'Table'[Hours] ), FILTER ( ALL ( 'Table' ), EOMONTH ( 'Table'[Payroll End Date], 0 ) = EOMONTH ( MAX ( 'Table'[Payroll End Date] ), 0 ) && 'Table'[Employee ID] = MAX ( 'Table'[Employee ID] ) ) )I attach my sample below for your reference.
Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- pbi-noviceHelper I
I am a little confused on what you are trying to achieve.
Correct me if I'm wrong:
Input
10/02 -> 40hrs
10/09 -> 40hrs
10/16 -> 40hrs
10/23 -> 40hrs
Result
October 2022 -> 160hrs
- AlexD123New Member
Hi thanks for the reply. That is correct. However I want my empleriodhrs field to show the 160
- pbi-noviceHelper I
Hi Alex,
This can be solved using Power Query(I don't know DAX well enough to give that solution, I'm sure someone else can chime in for that).
Steps:
- Added a "MonthYearCode" column to the original "Table".
- This column combined month and year as a text. 10/23/22 -> 102022
- Duplicated "Table"
- Removed duplicates from the Payroll End Date
- Group By:
- "MonthYearCode"
- Sum "EmpPeriodHrs" as "TotalEmpPeriodHrs"
- Go to original "Table" and merge by "MonthYearCode" column.
- Expand the table (You only need to select "TotalEmpPeriodHrs")
Final Result of Duplicate Table
Final Result of original Table
This should will give you the total payroll hours by month and year per row.
- Added a "MonthYearCode" column to the original "Table".
- v-yanjiang-msftCommunity Support
Hi AlexDawson1111 ,
According to your description, I create a sample with two employees.
Here's my solution, create a calculated column.
Column = CALCULATE ( SUM ( 'Table'[Hours] ), FILTER ( 'Table', EOMONTH ( 'Table'[Payroll End Date], 0 ) = EOMONTH ( EARLIER ( 'Table'[Payroll End Date] ), 0 ) && 'Table'[Employee ID] = EARLIER ( 'Table'[Employee ID] ) ) )Result:
If you want to display the result in a visual, a measure can also work:
Measure = CALCULATE ( SUM ( 'Table'[Hours] ), FILTER ( ALL ( 'Table' ), EOMONTH ( 'Table'[Payroll End Date], 0 ) = EOMONTH ( MAX ( 'Table'[Payroll End Date] ), 0 ) && 'Table'[Employee ID] = MAX ( 'Table'[Employee ID] ) ) )I attach my sample below for your reference.
Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.