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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Tinus1905
Resolver I
Resolver I

powerbi remove newest time duplicates

Hi,

 

In PowerBi I have a table with duplicate values. I want to remove the duplicates so the oldest would be deleted. 

You can see that Peter worked on 25-10-2023 13:41 with working hours of 08:00. The manager changed this to 09:30 on 25-10-2023 17:05. The first one must be deleted. Harry worked on 26-10-2023 but it is listed twice (27-10-2023 13:41 and 27-10-2023 16:45). The oldest date and time must be deleted. 

Sometimes a agent worked twice a day. Harry worked on 26-10-2023 from 12:00 - 17:00 and from 18:00 - 22:00. Now nothing must be deleted. 

Is it possible to achieve this?

 

Tinus1905_0-1703843404317.png

 

 

1 ACCEPTED SOLUTION

@Tinus1905 open Blad1 in Advanced Editor and replace everything with the following: 

 

let
    Source = Excel.Workbook(File.Contents("\\dc01\Users\martijnb\Desktop\Hours 2.xlsx"), null, true),
    Blad1_Sheet = Source{[Item="Blad1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Blad1_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date added", type datetime}, {"Workdate", type date}, {"Name", type text}, {"Starttime", type time}, {"endtime", type time}, {"total changed by manager", type time}, {"Namecode", type text}, {"Factory", type text}}),
    g = Table.Group(#"Changed Type", {"Workdate", "Name", "Starttime"}, {{"all", each Table.LastN(Table.Sort(_, "Workdate"), 1)}}),
    combine = Table.Combine(g[all])
in
    combine

 

View solution in original post

12 REPLIES 12
Syndicate_Admin
Administrator
Administrator

This outcomes in an elevated degree of authenticity with exact light dispersion and reflections.

Fowmy
Super User
Super User

@Tinus1905 

Copy your Excel data and paste it in your reply to this message so we can use it to test the solution.


Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Is this ok?

@Tinus1905 

No, you have pasted a picture. 

Sharing a dummy Power BI file representing your scenario would be beneficial. You can save the Power BI file or the Excel file on Google Drive or any other cloud storage platform and provide the link here. Kindly ensure that permission is granted to open the file.

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Tinus1905 requests access to your file... Group by name, workday, starttime (maybe + endtime). Sort each group by  date added and take either first or last row (Table.FirstN or Table.LastN) depending on sorting order.

Table.Group(tbl_name, {"Workdate", ..., "endtime"}, {"groups", each Table.LastN(Table.Sort(_, "Date added"), 1) and then combine groups into new table: Table.Combine(step_above[groups])  

@AlienSx you can access the file.

I don't quite understand what you mean, but probably when I see it in the file it will become clear. 

@Tinus1905 open Blad1 in Advanced Editor and replace everything with the following: 

 

let
    Source = Excel.Workbook(File.Contents("\\dc01\Users\martijnb\Desktop\Hours 2.xlsx"), null, true),
    Blad1_Sheet = Source{[Item="Blad1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Blad1_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date added", type datetime}, {"Workdate", type date}, {"Name", type text}, {"Starttime", type time}, {"endtime", type time}, {"total changed by manager", type time}, {"Namecode", type text}, {"Factory", type text}}),
    g = Table.Group(#"Changed Type", {"Workdate", "Name", "Starttime"}, {{"all", each Table.LastN(Table.Sort(_, "Workdate"), 1)}}),
    combine = Table.Combine(g[all])
in
    combine

 

@Fowmy and @AlienSx thanks for the help. It works great!! 

Date addedWorkdateNameStarttimeendtimetotal changed by managerNamecodeFactory
25-10-2021 13:4125-10-2023Peter09:0017:0008:00PRBase 1
25-10-2021 17:0525-10-2023Peter09:0017:0009:30PRBase 1
25-10-2021 17:0523-10-2023Harry09:0017:0008:00HYStation 1
26-10-2021 13:4126-10-2023Peter09:0017:0008:00PRBase 1
27-10-2021 13:4126-10-2023Harry12:0017:0005:00HYStation 1
27-10-2021 13:4126-10-2023Harry18:0022:0004:00HYStation 1
27-10-2021 16:4526-10-2023Harry18:0022:0004:00HYStation 1
27-10-2021 17:0527-10-2023Peter09:0017:0008:00PRBase 1
        
        
25-10-2021 17:0525-10-2023Peter09:0017:0009:30PRBase 1
25-10-2021 17:0523-10-2023Harry09:0017:0008:00HYStation 1
26-10-2021 13:4126-10-2023Peter09:0017:0008:00PRBase 1
27-10-2021 13:4126-10-2023Harry12:0017:0005:00HYStation 1
27-10-2021 16:4526-10-2023Harry18:0022:0004:00HYStation 1
27-10-2021 17:0527-10-2023Peter09:0017:0008:00PRBase 1

@Tinus1905 

Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps. Check the last two steps where I used custom code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rZHBCsIwDIZfpfTsoO3WTXcUkZ1k6EFkeIhrUdGtUHPZ29u5TURRinrpn6bJx5+0KOgMUBNQSis6omtjT8olXLiAqpUVgkU83mJdqz5Cg3Am5QHqvVZk15AKathr2/eVRrVVcyjR2IZuRwUVMuAsEExwwsM04u75ngrdJdd4a2eTlDGnPOmUjTvNl+6YwkUT/sJzpdKbN0lDX174wMvAukne+8s23bLwaOoBGb+OHP8ycvKZN1jk4okn31v0RfaWRI9mkRcyTiP5Z+TwN8m3i9xeAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t, #"(blank).5" = _t, #"(blank).6" = _t, #"(blank).7" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}, {"(blank).4", type text}, {"(blank).5", type text}, {"(blank).6", type text}, {"(blank).7", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date added", type text}, {"Workdate", type text}, {"Name", type text}, {"Starttime", type time}, {"endtime", type time}, {"total changed by manager", type time}, {"Namecode", type text}, {"Factory", type text}}),
    NoDups = Table.Distinct(#"Changed Type1", {"Workdate", "Name", "Starttime", "endtime", "total changed by manager"}),
    #"Grouped Rows" = Table.Combine(Table.Group( NoDups, {"Workdate", "Name", "Starttime", "endtime"}, {{"Change", each let maxtime = List.Max(_[total changed by manager]) in Table.SelectRows(_,each [total changed by manager]= maxtime) }})[Change])
in
    #"Grouped Rows"


Result:

Fowmy_0-1703936316781.png

 




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Tinus1905 

Please confirm if my solution worked for you? 
Feedback will be helful.

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.