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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
BenChain
Frequent Visitor

Maximum of row with dynamic columns

Hi helpers

 

I have been searching a few hours for this issue but cannot work it out. I have data like so

BenChain_0-1594903512339.png

I want to add a maximum column to get the highest value from these columns. Like so

 

= Table.AddColumn(#"Pivoted Column", "Maximum", each List.Max({[#"2019-9"], [#"2019-8"], [#"2019-7"], [#"2019-6"], [#"2019-5"], [#"2019-4"], [#"2019-3"], [#"2019-2"]}), type number)

 

My data however is dynamic and so the column names will change and may increase/decrease in count. 

 

I thought I could simply create a list and refer to that list like so

 

= Table.AddColumn(#"Pivoted Column", "Maximum", each List.Max(LISTNAME), type number)

 

but this does not work. All that does is give me the list names 

 
1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

Hi @BenChain ,

 

You can added an index to this table and create a column like:

let _index = [Index] in
List.Max(Table.Transpose(Table.RemoveColumns(Table.SelectRows(#"Added Index", each [Index] = _index), {"Index"}))[Column1])

 

Capture.PNG

 

Also, you can exclude the columns using the Table.RemoveColumns and leave only those you want to compare.

 

Ricardo 



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

4 REPLIES 4
camargos88
Community Champion
Community Champion

Hi @BenChain ,

 

You can added an index to this table and create a column like:

let _index = [Index] in
List.Max(Table.Transpose(Table.RemoveColumns(Table.SelectRows(#"Added Index", each [Index] = _index), {"Index"}))[Column1])

 

Capture.PNG

 

Also, you can exclude the columns using the Table.RemoveColumns and leave only those you want to compare.

 

Ricardo 



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Thank you, this worked for me perfectly!

Anonymous
Not applicable

try also this:

 

Table.AddColumn(Source, "max", each List.Max(Record.FieldValues(_)))

Greg_Deckler
Super User
Super User

@BenChain - With column names changing, that could prove difficult in Power Query. @ImkeF or @edhans may be of assistance. However, when you have that kind of data layout you generally want to unpivot those columns so that you end up with 2 columns. That's generally a recipe for success. Then, if you want the maximum, it pretty much becomes dirt simple.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors
Top Kudoed Authors