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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Group different rows into one (same data)

Hi all.

 

I need to be able to group different rows, which correspond to the same data, into one. In the image you can see that SHIPMENTID and HUUID is the same for the 3 columns, the only difference is the extraction date. I need the data to look like desidered image.
The idea is to be able to transform 3 rows into 1, by ordering waypoits_actual as 1, 2, 3 in order of extraction date by naming 1frst , 2second and so on.... keeping always Wapoints at first. In case there are more just need to align the same...

Actual data: 

JoseBernardo_2-1660717382088.png

Source.NameShipmentIdHUUIDshipdateWaypointsWaypoints_actualExtraction_date__index_level_0__
DailyExtract_2022-08-01_part1.parquet130159218015faca5b3-ef53-347f-baf2-adc781156c3b30-Jul-22 KNUA-DE8-DEL-DELT8-CDGH-ETZA-XGBA1-Aug-2249253
DailyExtract_2022-07-30_part2.parquet130159218015faca5b3-ef53-347f-baf2-adc781156c3b30-Jul-22KNUA-DELRT-CDGH-ETZA-XGBA 30-Jul-221006581
DailyExtract_2022-07-31_part1.parquet130159218015faca5b3-ef53-347f-baf2-adc781156c3b30-Jul-22 KNUA-DE8-DEL-CDGH-ETZA-XGBA31-Jul-22292748

 

Desired data: 

JoseBernardo_0-1660717503263.png

Source.NameShipmentIdHUUIDshipdateWaypointsWaypoints_actual1frs REROUTE2nd rerouteExtraction_date__index_level_0__
 130159218015faca5b3-ef53-347f-baf2-adc781156c3b30-Jul-22KNUA-DELRT-CDGH-ETZA-XGBAKNUA-DE8-DEL-DELT8-CDGH-ETZA-XGBAKNUA-DE8-DEL-CDGH-ETZA-XGBAKNUA-DE8-DEL-DELT8-CDGH-ETZA-XGBA  

 

I have other columns that can be used to obtain what I need, such as Extraction date / index level (orders my dimesioal date table) etc..

Thanks!

@rohit_singh @Ashish_Mathur 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Anonymous 
I though I've had replied back to you with updated solution but for some reason I caanot see my reply. Heree is the sample file https://www.dropbox.com/t/mrD8taPTCHSWO8P2

Please try this solution if it works. However, this is not a perfect situation for a 17M rows data.

1.png

Shipments Summary 2 = 
VAR T1 = SUMMARIZE ( Shipments, Shipments[ShipmentId], Shipments[HUUID], "Waypoint", MAX ( Shipments[Waypoints] ) )
VAR T2 = 
    GENERATE ( 
        T1, 
        VAR T3 = CALCULATETABLE ( Shipments )
        VAR T4 = 
            ADDCOLUMNS ( 
                T3, 
                "@Rank", RANKX ( FILTER ( T3, [Waypoints_Actual] <> BLANK ( ) ), [Extraction_date] ) 
            )
        VAR FirstReroute = MAXX ( FILTER ( T4, [@Rank] = 2 ), [Waypoints_actual] )
        VAR SecondReroute = MAXX ( FILTER ( T4, [@Rank] = 1 ), [Waypoints_actual] )
        RETURN  
            ROW ( "1st Route", FirstReroute, "2nd Route", SecondReroute,"3rd Route", FirstReroute )
    )
RETURN
    T2

View solution in original post

36 REPLIES 36

I've added a dummy data to test if a column would be automatically created for each extract date.

danextian_0-1660720180730.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Thanks!

 

Well in fact my data source is an azure data lake..
This is the advance editor for my data source: 

JoseBernardo_0-1660719821839.png

Shall I jsut replace with the following on your M code? : 

Source = AzureStorage.DataLake("https://stdesignshpstatusraw.dfs.core.windows.net/sting-dailyextract-data"),

 

 

I've never tried connecting to a datalake so I am not sure how it is done. If you post the full M-script of connecting to a table in a datalake, I might have an idea.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

When i paste the code on a blanck query somethig seems to break , everything turns red. am i missing something?

JoseBernardo_0-1660720155547.png

 

Go to Advanced Editor, clear everything and paste the code. You can right-click the query  or select the query, go to Home tab and then Advanced Editor.

danextian_0-1660720313253.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Thanks! now seems to be working. But only aplly for 1 row.. how do i do to get all my data trough these ?  there is only one row after applying 

 

JoseBernardo_0-1660720598104.png

 

There is only one row because the data used was just your sample data, not the actual data. The Source step must be changed so it points to the actual data.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Clear, I have to figure out to change that. I am trying to replace de source and this shows up :  Like if " Waypoints" doesnt exist.... any clue?

JoseBernardo_0-1660721094897.png

 

It may not be actually Waypoints.

Exit the Advanced Editor and just click Source step. Post a screenshot of the columns.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

I also change the source...and now the " waypoints" issue its gone. 
Now is still loading all the steps, its a over 17 millions rows data...will take some time i guess..

JoseBernardo_0-1660723439980.png

 

I can imagine how slow my proposed solutions would be withi 17M rows of data. Grouping and th then creating an index column in each uid is essentially looping through each row of uid. Do you have other column that indicates the order of each extract date similar to below?

danextian_0-1660737334012.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Sorry I dont have any other column i have just checked  and that column does not ahve a unique value for every row.. 😞 Is there any way to solve it ?

Anonymous
Not applicable

Yes! i took to loong i had to quick it.

 

Well i have these other columns 

JoseBernardo_0-1660737686399.png

Index level its a column that i use to give order to a dim table like calendar table. I also have extraction date, and another date column...
its is usefull? 

Is there any way to do this but with out going trugh query editor? i mean its really capacity demanding..

 

I was looking for a column that shows the index of each entry per uid and not the index for the whole of the data source. That is so I can avoid having the create an index at each instance of uid. I can use that instead to create  of reroute + number.

 

The code below could be faster. It's the same as the originally with the last step removed. Instead of converting each reroute row to a column, they are to be shown in a matrix visual instead

danextian_0-1660741658108.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("vZBNC4JAEIb/y56bmA8316OlFBUdwiAKkdUyAg8lCvXv2z4gqOgUwbzDDDwDD7Neq8juq3N8ampbNBkjM6ABpOxg64a6rh/bbaM6igRJB0wGyW26tIXVucC21ALi+SXktmSwm8I3RLpXSO4wQRi3FTC72dVktgghio3L9JrEwCAajiBOViEsh/3QMUgQtrv7iRewFpV2Plr6IHiz5F9aPhSn8+Rd7QUlxJ429MXvD198kxR6whyw7xmVphc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Source.Name = _t, ShipmentId = _t, HUUID = _t, shipdate = _t, Waypoints = _t, Waypoints_actual = _t, Extraction_date = _t, __index_level_0__ = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,"",null,Replacer.ReplaceValue,{"Waypoints", "Waypoints_actual"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"Source.Name", type text}, {"ShipmentId", Int64.Type}, {"HUUID", type text}, {"shipdate", type date}, {"Waypoints", type text}, {"Waypoints_actual", type text}, {"Extraction_date", type date}, {"__index_level_0__", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Waypoints2", each if [Waypoints_actual] <> null then [Waypoints_actual] else [Waypoints], type text),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Waypoints", "Waypoints_actual", "__index_level_0__", "Source.Name"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Waypoints2", "Waypoints_actual"}}),
    #"Sorted Rows" = Table.Sort(#"Renamed Columns",{{"Extraction_date", Order.Ascending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"ShipmentId", "HUUID"}, {{"Grouped", each _, type table [ShipmentId=nullable number, HUUID=nullable text, shipdate=nullable date, Extraction_date=nullable date, Waypoints_actual=text]}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 0, 1, Int64.Type),
    #"Added Custom1" = Table.AddColumn(#"Added Index", "Grouped2", each let x = Table.AddIndexColumn([Grouped], "Index", 0, 1, Int64.Type),

AddCol = Table.AddColumn(x, "Route", each if [Index] = 0 then " Waypoints Actual"else "Reroute " & Text.From([Index] + 1) )
in  AddCol,  type table),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Custom1",{"Grouped", "Index"}),
    #"Expanded Grouped2" = Table.ExpandTableColumn(#"Removed Columns1", "Grouped2", {"shipdate", "Waypoints_actual", "Route"}, {"shipdate", "Waypoints_actual", "Route"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Grouped2",{{"shipdate", type date}, {"Waypoints_actual", type text},{"Route", type text}})
in
    #"Changed Type1"

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Ok i use that one, changing the source in advance editor ,on a query blanck. But takes to long to go trough all the process 😞 may be you can sahre me your email and we can have a call...maybe there is somthig else that me maight try...

Anonymous
Not applicable

I checked and its correct , is " Waypoints" , very strange

JoseBernardo_0-1660721896459.png

 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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