PQ: Max of absolute values in across columns

DRSteele

Well-known Member
Joined
Mar 31, 2015
Messages
2,640
Office Version
  1. 365
Platform
  1. Windows
Can someone please help me in Power Query?

I would like a custom column to report the maximum magnitude of values per record, in other words I would like the max absolute values. The column names are on row 30. It seems easy in Excel, but I can't figure out the syntax in PQ.

ABCDEFGHI
30Forecast
Day
1234567Max Magnitude
318/23/2017-2.1-0.1-0.1-1.1-1.1-3.1-6.16.1
328/24/2017-1.5-1.5-3.5-2.5-2.5-4.5-0.54.5
338/25/2017-0.2-0.2-0.2-1.2-1.2-1.2-1.21.2
348/26/2017-1.80.20.20.2-0.8-1.8-2.82.8
358/27/2017-2.1-1.1-2.1-1.1-1.1-3.1-5.15.1

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Query2

Array Formulas
CellFormula
I31{=MAX(ABS(B31:H31))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
You can add a column for Max by first selecting the columns 1..7 and then on the Add Column tab > Statistics > Max
and manual add function Number.ABS for all columns [1]..[7] in step #"Inserted Maximum" or copy next code:
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"no", Int64.Type}, {"Forecast Day", type text}, {"1", type number}, {"2", type number}, {"3", type number}, {"4", type number}, {"5", type number}, {"6", type number}, {"7", type number}}),
    #"Inserted Maximum" = Table.AddColumn(#"Changed Type", "Max", each List.Max({Number.Abs([1]), Number.Abs([2]), Number.Abs([3]), Number.Abs([4]), Number.Abs([5]), Number.Abs([6]), Number.Abs([7])}), type number)
in
    #"Inserted Maximum"

or shorter use List.Min function and Number.Abs around List.Min
 
Last edited:
Upvote 0
Thank you very much. I got it to work in my actual code, even though Add Column tab > Statistics > Max was greyed out.

But I don't understand why List.Min combined with Number.Abs would provide the maximum magnitude. Can you elaborate a bit for me?
 
Upvote 0
Some numbers are positive and some are zero. I wanted the largest absolute values, which I think we did.
 
Upvote 0
If the values are in the last 7 columns before adding the custom column, you can use:

Code:
let
    Source = Table1,
    #"Added Custom2" = Table.AddColumn(Source, "Max Magnitude", each List.Max(List.Transform(List.LastN(Record.FieldValues(_),7),Number.Abs)))
in
    #"Added Custom2"
 
Upvote 0
Terrific, thanks. I tried nesting those functions but I got all confused. It's too bad PQ doesn't have such a simple and obvious way to find the max, min or average absoute value.
 
Upvote 0

Forum statistics

Threads
1,214,388
Messages
6,119,226
Members
448,878
Latest member
Da9l87

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top