Forum Discussion
Trying to Scale/Normalize a value column from 1 to 100 based on min/max value in column
- 6 years ago
FYI that a DAX calculated column would also work and recalculate with each refresh too. But below is some M code that demonstrates how to do your calculation in the query. To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTKyUIrViVZyAjFNwExnENNAKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, Score = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"Score", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Normalized Score", each [Score]/List.Max(#"Changed Type"[Score])*100), #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Normalized Score", type number}}) in #"Changed Type1"If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
FYI that a DAX calculated column would also work and recalculate with each refresh too. But below is some M code that demonstrates how to do your calculation in the query. To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTKyUIrViVZyAjFNwExnENNAKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, Score = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"Score", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Normalized Score", each [Score]/List.Max(#"Changed Type"[Score])*100),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Normalized Score", type number}})
in
#"Changed Type1"
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
Hello
as it would be with a calculated column in DAX