PQ: Max of absolute values in across columns

DRSteele

Well-known Member
Joined
Mar 31, 2015
Messages
2,048
Office Version
365
Platform
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>
 

citizenbh

Board Regular
Joined
Sep 19, 2013
Messages
123
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:

DRSteele

Well-known Member
Joined
Mar 31, 2015
Messages
2,048
Office Version
365
Platform
Windows
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?
 

DRSteele

Well-known Member
Joined
Mar 31, 2015
Messages
2,048
Office Version
365
Platform
Windows
Some numbers are positive and some are zero. I wanted the largest absolute values, which I think we did.
 

MarcelBeug

Well-known Member
Joined
Apr 25, 2014
Messages
1,811
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"
 

DRSteele

Well-known Member
Joined
Mar 31, 2015
Messages
2,048
Office Version
365
Platform
Windows
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.
 

Forum statistics

Threads
1,082,287
Messages
5,364,312
Members
400,789
Latest member
Gnar

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top