cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Power Query - List.Min for one column based on duplicate values in another column

Hi Everyone,

 

Having some problems where I have row level data with duplicates values that I need to find a minimum value for.  In the below screenshot i would like to see a 3rd column that shows the minimum date difference for each "Ctr & Visit Code" value.

 

Is there a calculation in Power Query that i can use 

 

hazaboy9_0-1599108795709.png

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Continued Contributor
Continued Contributor

Re: Power Query - List.Min for one column based on duplicate values in another column

@hazaboy9 

 

Try below code in your advance editor/powerquery, it should work.

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lEyVIrVATKN4ExLOMsCIQ1SaQRhGsKZxghREygzFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Date Difference" = _t, #"Ctr & Visit Code" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date Difference", Int64.Type}, {"Ctr & Visit Code", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Ctr & Visit Code"}, {{"Count", each _, type table [Date Difference=nullable number, #"Ctr & Visit Code"=nullable number]}}),
#"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Custom.1", each List.First(List.Sort(Table.Column([Count],"Date Difference")))),
#"Expanded Count" = Table.ExpandTableColumn(#"Added Custom1", "Count", {"Date Difference"}, {"Count.Date Difference"})
in
#"Expanded Count"

 

Let me know if above makes sense

View solution in original post

Highlighted
Community Support
Community Support

Re: Power Query - List.Min for one column based on duplicate values in another column

Hi @hazaboy9 ,

 

Try to use "Group" by the "Ctr & Visit Code" column and return a column of min value of "Date Difference" column.

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Highlighted
Super User IV
Super User IV

Re: Power Query - List.Min for one column based on duplicate values in another column

@hazaboy9 ,

refer  if these can help

https://www.youtube.com/watch?v=rqDdnNxSgHQ

https://www.youtube.com/watch?v=qUmTxQHr6nY

 



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Highlighted
Continued Contributor
Continued Contributor

Re: Power Query - List.Min for one column based on duplicate values in another column

@hazaboy9 

 

Try below code in your advance editor/powerquery, it should work.

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lEyVIrVATKN4ExLOMsCIQ1SaQRhGsKZxghREygzFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Date Difference" = _t, #"Ctr & Visit Code" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date Difference", Int64.Type}, {"Ctr & Visit Code", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Ctr & Visit Code"}, {{"Count", each _, type table [Date Difference=nullable number, #"Ctr & Visit Code"=nullable number]}}),
#"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Custom.1", each List.First(List.Sort(Table.Column([Count],"Date Difference")))),
#"Expanded Count" = Table.ExpandTableColumn(#"Added Custom1", "Count", {"Date Difference"}, {"Count.Date Difference"})
in
#"Expanded Count"

 

Let me know if above makes sense

View solution in original post

Highlighted
Community Support
Community Support

Re: Power Query - List.Min for one column based on duplicate values in another column

Hi @hazaboy9 ,

 

Try to use "Group" by the "Ctr & Visit Code" column and return a column of min value of "Date Difference" column.

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Community Conference

Microsoft Power Platform Communities

Check out the Winners!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (989)