Forum Discussion

Mp1977's avatar
Mp1977
Icon for Helper II rankHelper II
6 years ago
Solved

Replace value with a value from other column

Hi guys, can someone help me out with the following problem? I have a Excel table that has the month valued merged for 3 columns and I need it in the Total Cell. What I Have in power query ...
  • ziying35's avatar
    6 years ago

    Mp1977 

    Try this:

    let
        Source = Table.FromRecords(Json.Document(Binary.Decompress(Binary.FromText("vZA9C8IwFEX/SshctU21H27aqiBYBQsO6hC0aDFNoDRDEf+7HbR9L3QUx9zcyzm845NGSuhCOnRKpRaCWp+AmYFrBuMmWCkuyIDsF7vTiNnt18Tsembgd+NtlKJxYHbDb/CyoG6ihsg24UWGbJdaXqpcSWQc81zU5Nagke1BlY/sSmJeI+dUVRxL9+yD/n3Y7pG3A503vKyR8wzKOsCQecCre/ig1Xc4G7EZZK/VXf6R7UJ2JLhG7PnP2ec3", BinaryEncoding.Base64),Compression.Deflate))),
        transp = Table.Transpose(Source),
        group = Table.Group(
                   transp, 
                   "Column1", 
                   {
                       "t", 
                       (tbl)=> Table.ReplaceValue(
                                    tbl, 
                                    each tbl[Column1]{0}, 
                                    each [Column2]="Total", 
                                    (x,y,z)=>if z then y else x, 
                                    {"Column2"}
                                )
                    },
                    0,
                    (x,y)=>Byte.From(Text.StartsWith(y, "Goal"))
                ),
        result = Table.Transpose(Table.Combine(group[t]))
    in
        result