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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
leandross89
Helper II
Helper II

How can I get the first value in a collumn

Hi Everybody,

 

I would like to create the collumn 1 and Collumn 2, as you can see the collumn 1 has a location and for each location I´d like to generate 1 number but repeating it for the same device. The collumn 2 I´d like to repeat the topo information of the device 1  for the others devices on the same location. 

 

LOCATIONDEVICETOPOCollumn 1Collumn 2
14005912G12G
14005924G12G
14005944G12G
14053414G24G
14053432G24G
14053442G24G
14070112G32G
14070124G32G

 

Could you help me?

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQxMDC1VNJRMgRiI3elWB0kMSMgNkETM0ERMzU2gepFFzNGMQ8iZoIiZm5giGEvRAxmbywA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [LOCATION = _t, DEVICE = _t, TOPO = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"LOCATION", Int64.Type}, {"DEVICE", Int64.Type}, {"TOPO", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"LOCATION"}, {{"All", each _, type table [LOCATION=nullable number, DEVICE=nullable number, TOPO=nullable text, Collumn 1=nullable number, Collumn 2=nullable text]}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each let ind = [Index] in Table.AddColumn([All], "Index", each ind)),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each let firsttopo = [All]{0}[TOPO] in Table.AddColumn([Custom], "FirstTOPO", each firsttopo)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom1",{"Custom.1"}),
    #"Expanded Custom.1" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom.1", {"LOCATION", "DEVICE", "TOPO", "Collumn 1", "Collumn 2", "Index", "FirstTOPO"}, {"LOCATION", "DEVICE", "TOPO", "Collumn 1", "Collumn 2", "Index", "FirstTOPO"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom.1",{{"LOCATION", Int64.Type}, {"DEVICE", Int64.Type}, {"TOPO", type text}, {"Collumn 1", Int64.Type}, {"Collumn 2", type text}, {"Index", Int64.Type}, {"FirstTOPO", type text}})
in
    #"Changed Type1"

 

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


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQxMDC1VNJRMgRiI3elWB0kMSMgNkETM0ERMzU2gepFFzNGMQ8iZoIiZm5giGEvRAxmbywA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [LOCATION = _t, DEVICE = _t, TOPO = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"LOCATION", Int64.Type}, {"DEVICE", Int64.Type}, {"TOPO", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"LOCATION"}, {{"All", each _, type table [LOCATION=nullable number, DEVICE=nullable number, TOPO=nullable text, Collumn 1=nullable number, Collumn 2=nullable text]}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each let ind = [Index] in Table.AddColumn([All], "Index", each ind)),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each let firsttopo = [All]{0}[TOPO] in Table.AddColumn([Custom], "FirstTOPO", each firsttopo)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom1",{"Custom.1"}),
    #"Expanded Custom.1" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom.1", {"LOCATION", "DEVICE", "TOPO", "Collumn 1", "Collumn 2", "Index", "FirstTOPO"}, {"LOCATION", "DEVICE", "TOPO", "Collumn 1", "Collumn 2", "Index", "FirstTOPO"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom.1",{{"LOCATION", Int64.Type}, {"DEVICE", Int64.Type}, {"TOPO", type text}, {"Collumn 1", Int64.Type}, {"Collumn 2", type text}, {"Index", Int64.Type}, {"FirstTOPO", type text}})
in
    #"Changed Type1"

 

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


is there any example to do in DAX?

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors