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
tm9918
Frequent Visitor

Add alternate row data in 2 new column

I have a data like below-

NameValue 
Service1.60E+12EPOCH Time
Service1094329.332Resp Time
Service1.60E+12EPOCH Time
Service1065677.9Resp Time
Service1.60E+12EPOCH Time
Service960574.6272Resp Time

 

and want to convert it as- 

NameEPOCH TimeResp Time
Service1.60E+121094329
Service1.60E+121065678
Service1.60E+121094329
Service1.60E+121065678
Service1.60E+121094329

 

In first table under column name 'Value' I have EPOCH Time and Resp Time for same service and it's alternate. I want to convert Value column to 2 new Columns of EPOCH Time and Resp Time.

 

Can someone please help

4 REPLIES 4
mahoneypat
Employee
Employee

Please see the M code below with an example of how to do this with your example data.  To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk4tKstMTlXSUTLUMzNw1TY0AjJdA/ydPRRCMnNTlWJ1UNQYWJoYG1nqGRuDlAWlFhdgVUWUSWamZubmepYUmmNpZmBqbqJnZmSO5qJYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Value = _t, Time = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Value", type number}, {"Time", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Inserted Multiplication" = Table.AddColumn(#"Added Index", "Multiplication", each Number.RoundUp([Index] / 2,0), type number),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Multiplication",{"Index"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Time]), "Time", "Value"),
    #"Rounded Off" = Table.TransformColumns(#"Pivoted Column",{{"Resp Time", each Number.Round(_, 0), type number}})
in
    #"Rounded Off"

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


HotChilli
Super User
Super User

You need to identify each pair.

 

In Power Query:

First, assign a name to the 3rd column.  Let's call it 'alt'

Add an Index column from 0.

Add a custom column , dividing the index by 2 (each Number.IntegerDivide([Index], 2))).

Remove the Index column.

Pivot on the 'alt', using Value column for Values.  I don't think it matters which aggregation you use.

 

Good luck.

@HotChilli - How can I do 'dividing the index by 2 (each Number.IntegerDivide([Index], 2)))'

@tm9918 

 

A bit of effort required at your side.  The code is provided.  Add a custom column.  Paste some code.  Debug it if it doesn't work.

 

I will help you if required.

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.