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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
MarkCorzo70
Regular Visitor

Problem with duplicate records

Hi all I have the following and i can't find the solution, any advice is appreciated

Tag             Div          Event       Date

77AK9Y       04             04         20012020

77AK9Y       04             05         20012020

23AG4G      04             04         20012020

Desired result:

77AK9Y       04             05         20012020

23AG4G      04             04         20012020

 

Meaning if the event 5 exists for a record don't want to consider the event 4

Thanks

1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @MarkCorzo70 

 

You can use Group By with Max on Event as per below.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjd39LaMVNJRMoFiIwMDQyMDIwOlWB00WVN0WSNjR3cTd6x6YwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Tag = _t, Div = _t, Event = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Tag", type text}, {"Div", Int64.Type}, {"Event", Int64.Type}, {"Date", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Tag", "Div", "Date"}, {{"Event", each List.Max([Event]), type number}})
in
    #"Grouped Rows"

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

View solution in original post

2 REPLIES 2
Jimmy801
Community Champion
Community Champion

Hello @MarkCorzo70 

 

this requires some writing of M-Code. I've prepared for you a solution that involves the Group-function with a special function, that filters for the max value in your Event-column. Check it out

let
	Source = #table
	(
		{"Tag","Div","Event","Date"},
		{
			{"77AK9Y","04    ","04   ","20012020"},	{"77AK9Y","04    ","05","20012020"},	{"23AG4G","04    ","04","20012020"}
		}
	),
    Group = Table.Group
	(
		Source, 
		{"Tag", "Div"}, 
		{{"AllRows", (tableint)=> let 
			RemoveColumns = Table.RemoveColumns(tableint, {"Tag", "Div"}),
			SelectMaxEvent = Table.SelectRows(RemoveColumns, each [Event]= List.Max(tableint[Event]))
		in 
			SelectMaxEvent,
		type table [Event=text, Date=text]}}
	),
    ExpandTable = Table.ExpandTableColumn(Group, "AllRows", {"Event", "Date"}, {"Event", "Date"})
in
	ExpandTable

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Mariusz
Community Champion
Community Champion

Hi @MarkCorzo70 

 

You can use Group By with Max on Event as per below.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjd39LaMVNJRMoFiIwMDQyMDIwOlWB00WVN0WSNjR3cTd6x6YwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Tag = _t, Div = _t, Event = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Tag", type text}, {"Div", Int64.Type}, {"Event", Int64.Type}, {"Date", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Tag", "Div", "Date"}, {{"Event", each List.Max([Event]), type number}})
in
    #"Grouped Rows"

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors