Forum Discussion

AlvinLy's avatar
AlvinLy
Helper II
2 years ago
Solved

Combine columns with different data types

Hello,   I have a scenario that i'm not sure if it's possible or not. I have a table with an identifier, codetype, and three value columns. See below: ActivityID CodeType ValueNumber ValueTe...
  • AlienSx's avatar
    AlienSx
    2 years ago

     

    let
        Source = your_table,
        merge = Table.CombineColumns(Source, {"ValueNumber", "ValueText", "ValueDate"}, (x) => List.RemoveNulls(x){0}, "x"),
        types = List.Zip(
            Table.ToColumns(
                Table.TransformColumns(
                    Table.Distinct(merge, "CodeType")[[CodeType], [x]], 
                    {"x", Value.Type}
                )
            )
        ),
        pvt = Table.Pivot(merge, List.Distinct(merge[CodeType]), "CodeType", "x"), 
        col_types = Table.TransformColumnTypes(pvt, types)
    in
        col_types