Power Query Transform a Column based on Another Column

前端 未结 6 1981
谎友^
谎友^ 2020-12-16 05:10

I keep thinking this should be easy but the answer is evading me. In Excel Power Query, I would like to transform the value in each row of a column based on another column\

6条回答
  •  时光取名叫无心
    2020-12-16 05:48

    Kudos to LoganTheSnowEater... I love your answer. You mentioned that it could be expanded upon for multiple actions and I wanted to post an example of how I successfully used it to do so:

    #"Patch Records" = Table.FromRecords(Table.TransformRows(#"Sorted Rows",
    (r) => Record.TransformFields( r, {
        {"Min Commit", each 
            if r[service_id] = "21430" then 81 else
            if r[service_id] = "24000" then 230 else
            if r[service_id] = "24008" then 18 else
            if r[service_id] = "24009" then 46.9 else
            _},
        {"Installed", each 
            if r[service_id] = "21430" then 90 else
            if r[service_id] = "24000" then 230 else
            if r[service_id] = "24008" then 18 else
            if r[service_id] = "24009" then 52 else
            _},
        {"Requested", each 
            if r[service_id] = "21430" then 90 else
            if r[service_id] = "24000" then 230 else
            if r[service_id] = "24008" then 18 else
            if r[service_id] = "24009" then 52 else
            _}})))
    

    My only surprise was that I had to reset all of the data types after I was done, but that makes sense in retrospect.

    p.s. I didn't have enough reputation points to post this as a comment to the solution

提交回复
热议问题