Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MXSven
Helper I
Helper I

Splitting a Column Pairwise

Hi,
I would like to transform a single column with value pairs into two columns,
but I am struggeling with this task:

 

MXSven_0-1647860576501.png

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSyMjWzMjVSitWJVjKzsADThlbGJlaGEDELS4iQoZWhsZWJKYRjZKYUGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Calculated Modulo" = Table.TransformColumns(#"Added Index", {{"Index", each Number.Mod(_, 2), type number}}),
    #"Added Index1" = Table.AddIndexColumn(#"Calculated Modulo", "Index.1", 0, 1, Int64.Type),
    #"Divided Column" = Table.TransformColumns(#"Added Index1", {{"Index.1", each _ / 2, type number}}),
    #"Rounded Down" = Table.TransformColumns(#"Divided Column",{{"Index.1", Number.RoundDown, Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Rounded Down", {{"Index", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Rounded Down", {{"Index", type text}}, "en-US")[Index]), "Index", "Data"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Index.1"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"0", "Timestamp"}, {"1", "Value"}})
in
    #"Renamed Columns"

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSyMjWzMjVSitWJVjKzsADThlbGJlaGEDELS4iQoZWhsZWJKYRjZKYUGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Calculated Modulo" = Table.TransformColumns(#"Added Index", {{"Index", each Number.Mod(_, 2), type number}}),
    #"Added Index1" = Table.AddIndexColumn(#"Calculated Modulo", "Index.1", 0, 1, Int64.Type),
    #"Divided Column" = Table.TransformColumns(#"Added Index1", {{"Index.1", each _ / 2, type number}}),
    #"Rounded Down" = Table.TransformColumns(#"Divided Column",{{"Index.1", Number.RoundDown, Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Rounded Down", {{"Index", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Rounded Down", {{"Index", type text}}, "en-US")[Index]), "Index", "Data"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Index.1"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"0", "Timestamp"}, {"1", "Value"}})
in
    #"Renamed Columns"

Thanks.

This works perfect.


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors