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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

Aggregate or Remove Rows based on Employee Numbers

I have a table with employee information including a start and end date. However, the table has multiple rows for employees that have left. For example, one row would just have the hire date and the second row would have a begining and end date. I want to remove the extra rows that every employee has one row which has the begining and end date. Is there a way to aggregatye the rows using unique employee IDs or to delete any duplicate rows that don't have a termination date? Here is what my current data looks like:

 EmployeeNumber.PNG

Here the first row for the employee doesn't show a temination date but the second row did. I would like this to just be the bottom highlighted row.

 

Thank you for your help.

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

You can do this in Power Query by counting the occurrences of the employee number and then filtering out any employee numbers that have two occurrences but no Last Work Date.

the code would look like

 

// Add column that counts occurences of employee number and assigns a "discard" value to employee numbers with 2 occurences and null LastWork Date
#"Added Custom" = Table.AddColumn(#"YourTablePreviousStep", "Count", each if List.Count(Table.SelectRows(#"Changed Type", (A) => [EA_Emp_N] = A[EA_Emp_N])[EA_Emp_N]) = 2 and [EE_LastWorkDayDt] = null then "Discard" else "Keep"),
// Filters Table to Keep disired rows
#"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Count] = "Keep")),
// Deletes the filter column that was added
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Count"})

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
jgeddes
Super User
Super User

You can do this in Power Query by counting the occurrences of the employee number and then filtering out any employee numbers that have two occurrences but no Last Work Date.

the code would look like

 

// Add column that counts occurences of employee number and assigns a "discard" value to employee numbers with 2 occurences and null LastWork Date
#"Added Custom" = Table.AddColumn(#"YourTablePreviousStep", "Count", each if List.Count(Table.SelectRows(#"Changed Type", (A) => [EA_Emp_N] = A[EA_Emp_N])[EA_Emp_N]) = 2 and [EE_LastWorkDayDt] = null then "Discard" else "Keep"),
// Filters Table to Keep disired rows
#"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Count] = "Keep")),
// Deletes the filter column that was added
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Count"})

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Anonymous
Not applicable

Thank you!

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors