Forum Discussion

Carlo1975's avatar
Carlo1975
Icon for Helper I rankHelper I
5 years ago
Solved

insert new calculated field

Hi, I have a table with 2 fields, one is the description and one is the amount related to description. But in some case our management system can.'t know if the description is equal to "buy" or to "...
  • Fowmy's avatar
    5 years ago

    Carlo1975 
    You can do it in a power query with simple steps and one custom column. Past the below code on a Blank Query on the Advanced Editr and check the :

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk7NyVHSUTI0NVCK1YlWciqtBPKMTM3APKikhaUpMtfcxASZa2hkhMw1MjVCMckYiWdoZAwxWNcQyDM1MEBwjEGcWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Description = _t, Amount = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Amount", type number}}),
        #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Description] <> "-1")),
        #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Description"}, {{"Total", each List.Sum([Amount]), type nullable number}}),
        #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Total", Order.Ascending}}),
        #"Kept First Rows" = Table.FirstN(#"Sorted Rows",1),
        Custom1 = #"Changed Type",
        #"Added Custom" = Table.AddColumn(Custom1, "Custom", each if [Description] = "-1" then #"Kept First Rows"[Description]{0} else [Description])
    in
        #"Added Custom"

     

    ________________________

    If my answer was helpful, please consider Accept it as the solution to help the other members find it

    Click on the Thumbs-Up icon if you like this reply šŸ™‚

    YouTube  LinkedIn