Forum Discussion

tpnkl's avatar
tpnkl
New Member
4 years ago
Solved

Two variations of first row text causing problems when used in column names

Hello,   I have data that comes into Power Query in two variations. Column 25 first row can be named 1) Temperature Deviation (°C) as in the sample data or 2) Temperature Deviation (°F).   When I...
  • Vijay_A_Verma's avatar
    4 years ago

    After your Source statement, this should be your second statement. This will change the column name to "Temperarure Deviation". Any processing like Change Type or anything should only after this statement. Insert this step in your query

    Table.TransformColumnNames(Source, (x)=>if Text.Contains(x,"Temperature Deviation") then "Temperature Deviation" else x)

    If you want to see this working - See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKVtJRcgNiE1OlWJ1opbR0IARyfYFY19hEKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Gender = _t, #"Temperature Deviation (°C)#(lf)" = _t]),
        Custom1 = Table.TransformColumnNames(Source, (x)=>if Text.Contains(x,"Temperature Deviation") then "Temperature Deviation" else x),
        #"Changed Type" = Table.TransformColumnTypes(Custom1,{{"Name", type text}, {"Gender", type text}, {"Temperature Deviation", Int64.Type}})
    in
        #"Changed Type"