SOLVED

Reference the maximum value of a column in Power Query

Iron Contributor

Hello,

I have a table in a Power Query, and would like to reference the maximum value of another column.

So let's say this is my table in Power Query:

IDValue

1

10
220
3

30

440
550
660
770
880

then I'd like to add a Custom Column "Range", with the formula

= if [Value]<0.33*MAX([Value]) then "0-33%" 
else if [Value]<0.66*MAX([Value]) then "33-66%"
else "66-100%"

but of course "MAX" isn't a formula in Power Query.

The end result should be something like (some ranges may be incorrect, but you get the idea)

IDValueRange

1

100-33%
2200-33%
3

30

0-33%

44033-66%
55033-66%
66033-66%
77066-100%
88066-100%

I'm not a Power Query Power User (as you have guessed), so preferably using functions in the ribbon...

8 Replies

@bartvana 

Before that add step like

maxValue = List.Max(prevStep[Value])

and use it in calculations

@bartvana 

here is the sample if hardcode ranges into the formula.

Thanks for your reply!

How much of that can be done without the advanced editor?

best response confirmed by bartvana (Iron Contributor)
Solution

@bartvana 

That significantly complicates the task. It could be like:

 

1) query source table

2) Reference source table, rename as maxValue

3) select in it Value column, Transform->Statistics->Maximum

4) Reference source table, rename reference as Range

5) Add Column -> Custom Column -> name as max -> =maxValue

6) Select Value column -> Add Column -> Standard -> Percentage Of -> from drop-down near Value select Use Value or column -> select max

7) Select Percent Of -> Transform -> Standard -> Divide -> 100

8) Transform -> Data Type -> Percentage

9) Add Column -> Conditional Column and here combine something like

image.png

10) Select columns ID, Value, Range

11) Home -> Remove Columns -> Remove Other Columns (from drop-down menu)

12) Home -> Close & Load To -> Table -> select desired options

 

@Sergei Baklan Could you clarify what you mean by "2) Reference source table" please?

@bartvana 

If you right click on any query you will see Reference in the menu

image.png

If click on it new query will be created with reference on first one

image.png

@Sergei Baklan Fabulous! It was the reference part that I didn't know about, your explanation makes it all very clear now. I reproduced your steps and understand now, thank you!

1 best response

Accepted Solutions
best response confirmed by bartvana (Iron Contributor)
Solution

@bartvana 

That significantly complicates the task. It could be like:

 

1) query source table

2) Reference source table, rename as maxValue

3) select in it Value column, Transform->Statistics->Maximum

4) Reference source table, rename reference as Range

5) Add Column -> Custom Column -> name as max -> =maxValue

6) Select Value column -> Add Column -> Standard -> Percentage Of -> from drop-down near Value select Use Value or column -> select max

7) Select Percent Of -> Transform -> Standard -> Divide -> 100

8) Transform -> Data Type -> Percentage

9) Add Column -> Conditional Column and here combine something like

image.png

10) Select columns ID, Value, Range

11) Home -> Remove Columns -> Remove Other Columns (from drop-down menu)

12) Home -> Close & Load To -> Table -> select desired options

 

View solution in original post