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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kjm5200
Regular Visitor

MinX Power M Query Equivalent

Hey All,

 

I am trying to figure out how to use the equivalent of the dax MinX formula using power m query.  I am aware how to accomplish this through Dax but its important that this is accomplished through power query. 

 

Below is a set of same data

 

SymbolDate
AA1-Jan
AA2-Jan
BB3-Jan
BB4-Jan
CC4-Jan
DD5-Jan

 

What I would like to see if 3 columns.  Column A is symbol, Column B is Date and Column 3 is the min date by symbol ignoring other columns.  The desired result is below.

 

SymbolDateMin Date
AA1-Jan1-Jan
AA2-Jan1-Jan
BB3-Jan3-Jan
BB4-Jan3-Jan
CC4-Jan4-Jan
DD5-Jan5-Jan

 

Can anyone help?  Thank you in advance!

 

Kevin

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

The key here to is perform a GroupBy with a Minimum aggregate on the data, and then merge the result back to the table before you grouped it.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRU0lEy1DXUNTIwtFCK1YGLGCFEnJzAIsYYIiYIEWdndBEXF7CIKVQkFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Group = _t, Date = _t]),
    TypeChange = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    Group = Table.Group(TypeChange, {"Group"}, {{"MinDate", each List.Min([Date]), type date}}),
    Merge = Table.NestedJoin(TypeChange,{"Group"},Group,{"Group"},"TypeChange",JoinKind.LeftOuter),
    Expand = Table.ExpandTableColumn(Merge, "TypeChange", {"MinDate"}, {"MinDate"})
in
    Expand

 

 

image.pngimage.pngimage.pngimage.png

View solution in original post

1 REPLY 1
Anonymous
Not applicable

The key here to is perform a GroupBy with a Minimum aggregate on the data, and then merge the result back to the table before you grouped it.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRU0lEy1DXUNTIwtFCK1YGLGCFEnJzAIsYYIiYIEWdndBEXF7CIKVQkFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Group = _t, Date = _t]),
    TypeChange = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    Group = Table.Group(TypeChange, {"Group"}, {{"MinDate", each List.Min([Date]), type date}}),
    Merge = Table.NestedJoin(TypeChange,{"Group"},Group,{"Group"},"TypeChange",JoinKind.LeftOuter),
    Expand = Table.ExpandTableColumn(Merge, "TypeChange", {"MinDate"}, {"MinDate"})
in
    Expand

 

 

image.pngimage.pngimage.pngimage.png

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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