Forum Discussion
cottrera
4 years agoPost Prodigy
MAX multiple columns per row
Hi
I have a table that has individual property addresses per row. The table contains multiple columns populated with years. I would like to add an additional columns that shows the MAX of all these columns per row.
I will also be using this result in a filter.
| Property Reference | ASBE | ELEC | GUTT | K&B | REDECS | ROOF | Custom Max |
| 3634 | 2011 | 2013 | 2020 | 2018 | 2017 | 2020 | |
| 606 | 2019 | 2020 | 2010 | 2021 | 2021 | ||
| 1979 | 2016 | 2010 | 2015 | 2016 | |||
| 4442 | 2012 | 2017 | 2020 | 2020 | |||
| 2137 | 2013 | 2021 | 2021 | ||||
| 2530 | 2017 | 2011 | 2015 | 2017 | |||
| 581 | 2015 | 2015 | |||||
| 483 | 2016 | 2013 | 2012 | 2020 | 2020 | ||
| 1179 | 2019 | 2019 | |||||
| 4472 | 2012 | 2011 | 2012 | ||||
| 1497 | 2010 | 2010 | |||||
| 2254 | 2020 | 2017 | 2020 | ||||
| 3303 | 2013 | 2017 | 2018 | 2018 | |||
| 3266 | 2012 | 2012 |
thank you
Richard
Here's one possible option
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZFLDgQhCESv0nHdCynwdxbT97/GzKARdHphSskLVWDvgTNLuAMi0RBWQRyvOqR85QrP3UOOWe9abhs7BLRYaqUZnI2albRIEYHV4U2XwyBBbHUNexlm1kjsjIpNeHn7H5kqnYn80XSVtxH4jOryEfmZ23s/Kdij4AyoraS5UeNrKyDJvia3OMOYowvN/5h+tZLI+XCa+Wa35wM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Property Reference" = _t, ASBE = _t, ELEC = _t, GUTT = _t, #"K&B" = _t, REDECS = _t, ROOF = _t]), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Property Reference"}, "Attribute", "Value"), #"Grouped Rows" = Table.Group(#"Unpivoted Other Columns", {"Property Reference"}, {{"Custom Max", each List.Max([Value]), type text}}), #"Merged Queries" = Table.NestedJoin(Source, {"Property Reference"}, #"Grouped Rows", {"Property Reference"}, "Grouped Rows", JoinKind.Inner), #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"Custom Max"}, {"Custom Max"}) in #"Expanded Grouped Rows"How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".
2 Replies
- lbendlinSuper User
Here's one possible option
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZFLDgQhCESv0nHdCynwdxbT97/GzKARdHphSskLVWDvgTNLuAMi0RBWQRyvOqR85QrP3UOOWe9abhs7BLRYaqUZnI2albRIEYHV4U2XwyBBbHUNexlm1kjsjIpNeHn7H5kqnYn80XSVtxH4jOryEfmZ23s/Kdij4AyoraS5UeNrKyDJvia3OMOYowvN/5h+tZLI+XCa+Wa35wM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Property Reference" = _t, ASBE = _t, ELEC = _t, GUTT = _t, #"K&B" = _t, REDECS = _t, ROOF = _t]), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Property Reference"}, "Attribute", "Value"), #"Grouped Rows" = Table.Group(#"Unpivoted Other Columns", {"Property Reference"}, {{"Custom Max", each List.Max([Value]), type text}}), #"Merged Queries" = Table.NestedJoin(Source, {"Property Reference"}, #"Grouped Rows", {"Property Reference"}, "Grouped Rows", JoinKind.Inner), #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"Custom Max"}, {"Custom Max"}) in #"Expanded Grouped Rows"How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".