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
peterso
Helper II
Helper II

Power Query Custom Column HELP

Hi all,

 

I'd like to create a column that returns a True / False based on the minimum value in a column per each type. I'm not the best at explaining - please take a look at the example:

 

peterso_0-1613955829285.png

 

Thanks for taking a look!

1 ACCEPTED SOLUTION
PC2790
Community Champion
Community Champion

Here is a step by step way to do it in Power Query:

1) Group by the columns to get the max value, somethin like below:

PC2790_0-1613973141662.png

PC2790_1-1613973333311.png

 

2) Apply a left outer join to merge the main table and the grouped by table:

= Table.NestedJoin(#"Changed Type", {"Value","Type"}, #"Grouped Rows", {"New","Type"}, "Grouped Rows", JoinKind.LeftOuter)

PC2790_2-1613973607001.png

3) Now expand the columns to get final Result column:

= Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"New"}, {"Result"})

 

PC2790_3-1613973960607.png

4) Now replace the values as per your requirement

= Table.ReplaceValue(#"Expanded Grouped Rows", each [Result],each if [Result] = null then "False" else "True",Replacer.ReplaceValue,{"Result"})

PC2790_4-1613974019351.png

Complete M Code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCs5PzlbSUTJUitUBcjIyi0qAPGMUnikKzxLKy08tRlIJ4QFNiQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}, {"Value", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Type"}, {{"New", each List.Min([Value]), type nullable number}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Value","Type"}, #"Grouped Rows", {"New","Type"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"New"}, {"Result"}),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded Grouped Rows", each [Result],each if [Result] = null then "False" else "True",Replacer.ReplaceValue,{"Result"})
in
    #"Replaced Value"

View solution in original post

2 REPLIES 2
PC2790
Community Champion
Community Champion

Here is a step by step way to do it in Power Query:

1) Group by the columns to get the max value, somethin like below:

PC2790_0-1613973141662.png

PC2790_1-1613973333311.png

 

2) Apply a left outer join to merge the main table and the grouped by table:

= Table.NestedJoin(#"Changed Type", {"Value","Type"}, #"Grouped Rows", {"New","Type"}, "Grouped Rows", JoinKind.LeftOuter)

PC2790_2-1613973607001.png

3) Now expand the columns to get final Result column:

= Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"New"}, {"Result"})

 

PC2790_3-1613973960607.png

4) Now replace the values as per your requirement

= Table.ReplaceValue(#"Expanded Grouped Rows", each [Result],each if [Result] = null then "False" else "True",Replacer.ReplaceValue,{"Result"})

PC2790_4-1613974019351.png

Complete M Code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCs5PzlbSUTJUitUBcjIyi0qAPGMUnikKzxLKy08tRlIJ4QFNiQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}, {"Value", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Type"}, {{"New", each List.Min([Value]), type nullable number}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Value","Type"}, #"Grouped Rows", {"New","Type"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"New"}, {"Result"}),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded Grouped Rows", each [Result],each if [Result] = null then "False" else "True",Replacer.ReplaceValue,{"Result"})
in
    #"Replaced Value"
Anonymous
Not applicable

Hi @peterso 

 

Paste it to Advanced Editor:

 

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "i45WCs5PzlbSUTJUitUBcjIyi0qAPGMUnikKzxLKy08tRlIJ4QFNiQUA",
          BinaryEncoding.Base64
        ),
        Compression.Deflate
      )
    ),
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [Type = _t, Value = _t]
  ),
  #"Changed Type" = Table.TransformColumnTypes(Source, {{"Type", type text}, {"Value", Int64.Type}}),
  MinValue = Table.Group(
    #"Changed Type",
    {"Type"},
    {{"Min", each List.Min([Value]), type nullable number}}
  ),
  #"Merged Queries" = Table.NestedJoin(
    #"Changed Type",
    {"Type"},
    MinValue,
    {"Type"},
    "Changed Type",
    JoinKind.LeftOuter
  ),
  #"Expanded Changed Type" = Table.ExpandTableColumn(
    #"Merged Queries",
    "Changed Type",
    {"Min"},
    {"Min"}
  ),
  #"Added Custom" = Table.AddColumn(#"Expanded Changed Type", "Result", each [Value] = [Min]),
  #"Removed Columns" = Table.RemoveColumns(#"Added Custom", {"Min"})
in
  #"Removed Columns"

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.