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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
cottrera
Post Prodigy
Post Prodigy

Power Query - Concatenate field with field above row by row

Hi Community , I have the following table.   The table is in the following order

1-Job#

2- Start Date

3-Input time as time type

In power query I would like to always start with the second row of each new 'Job#' and concatenate the the column called 'analysis' starting from the fist row of each job number and concatenate the 'analysis' of the next row down. This needs to be repeated  until the rows stop for each 'Job#'. 

I have added an example of the output I would expect on the end column .
Thank you Richard

 

Date LoggedJob#AgeOfJobInWorkingDaysaudit actionStartDateEndDateInput time as time typeWhoChangedItAnalysis
Column I
TotalDurationInStatus**Power Query**
02/01/20238241424 JOB_CREATE02/01/202302/01/202311:07:30John SmithAwaiting0 
02/01/20238241424 JOB_UPDATE02/01/202304/01/202311:08:11John SmithAwaiting2Awaiting-Awaiting
02/01/20238241424 JOB_UPDATE04/01/202309/01/202312:15:22Avril JonesAwaiting5Awaiting-Awaiting
02/01/20238241424 JOB_UPDATE09/01/202309/01/202311:39:49Avril JonesAwaiting0Awaiting-Awaiting
02/01/20238241424 JOB_UPDATE09/01/202309/01/202311:40:00Avril JonesAwaiting0Awaiting-Awaiting
02/01/20238241424 APPT_SCHD09/01/202303/02/202311:40:48Avril JonesScheduled25Awaiting-Scheduled
02/01/20238241424 JOB_UPDATE03/02/202303/02/202317:04:03BACKUPScheduled0Scheduled-Scheduled
02/01/20238241432 JOB_CREATE02/01/202302/01/202311:15:31John SmithAwaiting0 
02/01/20238241432 JOB_UPDATE02/01/202304/01/202311:15:50John SmithAwaiting2Awaiting-Awaiting
02/01/20238241432 JOB_UPDATE04/01/202304/01/202312:01:47Avril JonesAwaiting0Awaiting-Awaiting
02/01/20238241432 JOB_UPDATE04/01/202304/01/202312:05:07Avril JonesAwaiting0Awaiting-Awaiting
02/01/20238241432 APPT_SCHD04/01/202323/01/202312:05:41Avril JonesScheduled19Awaiting-Scheduled
03/01/20238242000 JOB_CREATE03/01/202303/01/202309:54:35Tony BanhamAwaiting0 
03/01/20238242000 JOB_UPDATE03/01/202311/01/202309:54:50Tony BanhamAwaiting8Awaiting-Awaiting
03/01/20238242000 APPT_SCHD11/01/202318/01/202311:24:07Christine FoskettScheduled7Awaiting-Scheduled
03/01/20238242000 APPT_CANCL18/01/202318/01/202309:55:53Shaine MastertonAwaiting0Scheduled-Awaiting
03/01/20238242000 APPT_SCHD18/01/202301/02/202309:56:05Shaine MastertonScheduled14Awaiting-Scheduled
03/01/20238242000 APPT_CANCL01/02/202303/02/202311:59:18BACKUPAwaiting2Scheduled-Awaiting
03/01/20238242000 JOB_UPDATE03/02/202316/02/202310:27:33PRATCHSXAwaiting13Awaiting-Awaiting
03/01/20238242000 APPT_SCHD16/02/202315/03/202311:20:14Christine FoskettScheduled27Awaiting-Scheduled
03/01/20238242000 APPT_CANCL15/03/202321/03/202314:49:05BACKUPAwaiting6Scheduled-Awaiting
03/01/20238242000 JOB_UPDATE21/03/202329/03/202317:00:26Christine FoskettAwaiting8Awaiting-Awaiting
03/01/20238242000 APPT_SCHD29/03/202312/04/202314:55:33Christine FoskettScheduled14Awaiting-Scheduled
03/01/20238242000 JOB_COMPL12/04/202328/04/202316:22:48BACKUPComplete16Scheduled-Complete
03/01/20238242000 JOB_UPDATE28/04/202328/04/202314:43:41Christine FoskettComplete0Complete-Complete
03/01/20238242323 JOB_CREATE03/01/202303/01/202310:27:20Jazaib SakenderAwaiting0 
03/01/20238242323 APPT_SCHD03/01/202303/01/202310:27:24Jazaib SakenderScheduled0Awaiting-Scheduled
03/01/20238242323 JOB_UPDATE03/01/202324/01/202310:27:54Jazaib SakenderScheduled21Scheduled-Scheduled
03/01/20238242802 JOB_CREATE03/01/202303/01/202311:20:39HEWITTNXAwaiting0Scheduled-Awaiting
03/01/20238242802 APPT_SCHD03/01/202303/01/202311:21:40HEWITTNXScheduled0Awaiting-Scheduled
03/01/20238242802 JOB_UPDATE03/01/202303/01/202311:22:00HEWITTNXScheduled0Scheduled-Scheduled
03/01/20238242802 APPT_CANCL03/01/202303/01/202315:12:46Shaine MastertonAwaiting0Scheduled-Awaiting
03/01/20238242802 APPT_SCHD03/01/202305/01/202315:13:06Shaine MastertonScheduled2Awaiting-Scheduled

 

1 ACCEPTED SOLUTION

Hi @cottrera 

 

Give this a go. Open the Advanced Editor select the last 2 lines of code, that's this part

in
#"Replaced Value"

 

Paste this in its place, it's important that the column "Analysis" from your sample corresponds to a column with the same name in your production data. If not, you need to update that name in the code below.

    GroupRows = Table.Group(#"Replaced Value", {"Job#"}, {{"t", each Table.AddColumn( Table.AddIndexColumn( _, "i", 0, 1), "Result", (x)=> if x[i]-1 <0 then "" else Text.Combine( List.Range([Analysis], x[i]-1, 2), "-"))}}),
    t = Table.Combine( GroupRows[t] )
in
    t

 

I hope this is helpful

View solution in original post

4 REPLIES 4
cottrera
Post Prodigy
Post Prodigy

Amazing thank you 😀 works perfectly 

cottrera
Post Prodigy
Post Prodigy

Hi M_dekote for you fast response. Looks like the m-code solves my problem.  However I made a slight error on the sample table I sent. There are some additional columns

 

Due_Overdue
Current Job Status
Trade
UniqueReference
UPRN
Work Stream
Agent

 

And I also have the following transformation in my existing code.
et
Source = Sql.Database("xxxx", "xxxx"),
Repairs_JobStatusChangesFromAuditTable = Source{[Schema="Repairs",Item="JobStatusChangesFromAuditTable"]}[Data],
#"Removed Columns" = Table.RemoveColumns(Repairs_JobStatusChangesFromAuditTable,{"Job Status", "Input User"}),
#"Merged Queries with Repairs" = Table.NestedJoin(#"Removed Columns", {"Repairs Request Ref"}, Repairs, {"Repairs Request Ref"}, "Repairs", JoinKind.LeftOuter),
#"Expanded Repairs" = Table.ExpandTableColumn(#"Merged Queries with Repairs", "Repairs", {"AgeOfJobBuckets", "AgeOfJobInWorkingDays", "Date Logged", "Due_Overdue", "Job Status Description", "Trade", "UniqueReference", "Unit Reference", "Work Stream"}, {"AgeOfJobBuckets", "AgeOfJobInWorkingDays", "Date Logged", "Due_Overdue", "Job Status Description", "Trade", "UniqueReference", "Unit Reference", "Work Stream"}),
#"Renamed Columns" = Table.RenameColumns(#"Expanded Repairs",{{"Job Status Description", "Current Job Status"}}),
#"Merged Queries with Agents" = Table.NestedJoin(#"Renamed Columns", {"UniqueReference"}, Agents, {"Unique"}, "Agents", JoinKind.LeftOuter),
#"Expanded Agents" = Table.ExpandTableColumn(#"Merged Queries with Agents", "Agents", {"Agent"}, {"Agent"}),
// By Reactive & Routine
#"Filtered Rows" = Table.SelectRows(#"Expanded Agents", each ([Work Stream] = "REACTIVE" or [Work Stream] = "REACTIVE_A" or [Work Stream] = "REACTIVE_B" or [Work Stream] = "ROUTINE_EXTERNAL" or [Work Stream] = "ROUTINE_INTERNAL" or [Work Stream] = "SMALLWORKS")),
#"Renamed Columns1" = Table.RenameColumns(#"Filtered Rows",{{"Repairs Request Ref", "Job#"}, {"Unit Reference", "UPRN"}}),
#"Replaced Value" = Table.ReplaceValue(#"Renamed Columns1","","N/A",Replacer.ReplaceValue,{"Due_Overdue"})
in
#"Replaced Value"

How would you suggest I both add the addtional columns to your code and also add your code after my code (mine obviously is using the UI)
Thanks Again
Richard

Hi @cottrera 

 

Give this a go. Open the Advanced Editor select the last 2 lines of code, that's this part

in
#"Replaced Value"

 

Paste this in its place, it's important that the column "Analysis" from your sample corresponds to a column with the same name in your production data. If not, you need to update that name in the code below.

    GroupRows = Table.Group(#"Replaced Value", {"Job#"}, {{"t", each Table.AddColumn( Table.AddIndexColumn( _, "i", 0, 1), "Result", (x)=> if x[i]-1 <0 then "" else Text.Combine( List.Range([Analysis], x[i]-1, 2), "-"))}}),
    t = Table.Combine( GroupRows[t] )
in
    t

 

I hope this is helpful

m_dekorte
Super User
Super User

Hi @cottrera,

 

Give this a go.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tZdbb9owFMe/SsReO+FbIPEbDUylazvUULVSVVVuiZqokCAw27pPvxNnAjv3FPZQYZPg3zl/n1sfH3tjIQPrKnl7Cxa9s95l8vIFPsRuEUlLvMooiWHrS7GR6YuwnsSLf6tpvN5JS0arwBLb7FN+rNMn92HihSKGI6cStqNYLD+20RaW80SK5Xi3EenJ0xgOlrv0++D3OniVYMLT2WMPkT7CfYIIhScOYZgRltr24/zZu52M5hPYGO8YG4w5GnKKlDdhbPmrSIapFb9EJKP4LX0f/qwm1N1sXIZiOZTDMa5BEW37df99a7ROQ66OJhzbnKjjf26ipXWZxMHWZNvHsd1KNubU5cytY6P/x2aII3RS9mg2mz/73sW4gKZ9+ImBZk4B7b+GwWK3VAlEDNEPT1p7rhNN/JAjxlG6PB953+9mOTLS941kSjplFMQarQvzuozao9plFKDsuuTtklElaFaJJhzBDQ9PFVld2TaUrZOyjajWaYQW0AzXRjV2a6KamnSCVHaasUVzSaUlN7cZp7bqDfGHdS7iUKwqg6uaZWSQFk8FlgquSpZTrXI5W1fZoGHHjGvCsgv2wk20hVMD61uyfQ+kzGk97Cy1MsEb3XhXBayTcx9yK136oUgNuBZbGWyk6vE5vQ+VpLMIBhPr5QwMGEC0lRtgxBs7TgQTmyvitsuxo1fRXHHp5np19cYDfYM4gakkXc5uR3Pvwn8wyZgeFXkGy+7DT7TIQ1wJ2hR55NjQ07kE60YwGBeymy9TfXCc6gaKuDoXeiYIP6hw/lR5bzKhGjPNccg5de1N6n8i5lWN/XE9u8pjiaPbMIA5MZtb9uJ7yWq9DNQYj031909aq+9UguHWadZaypzXbEDatsECqlYtu0uWdUTZLP6I6MXyxXsQL4JN6w6T8Yxe2oRjpbj8rNb2qg8Ol7c4wgoW2M0WENyrGRfzNjioOC5Wq6AqDk1HhovJ/XQ+v3koqt023TNyS/kBnM7oJvizuh98Lte9gCbZvyU16I56my2tmm1zGOKYSuOT9fUm3e2cAZSjCgOMqKvQ/+kv", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).3" = _t, #"(blank).4" = _t, #"(blank).5" = _t, #"(blank).6" = _t, #"(blank).7" = _t, #"(blank).8" = _t, #"(blank).9" = _t, #"(blank).10" = _t]),
    PromoteHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    GroupRows = Table.Group(PromoteHeaders, {"Job#"}, {{"t", each Table.AddColumn( Table.AddIndexColumn( _, "i", 0, 1), "Result", (x)=> if x[i]-1 <0 then "" else Text.Combine( List.Range([Analysis], x[i]-1, 2), "-")), type table [Date Logged=nullable text, #"Job#"=nullable text, audit action=nullable text, StartDate=nullable text, EndDate=nullable text, Input time as time type=nullable text, WhoChangedIt=nullable text, Analysis=nullable text, TotalDurationInStatus=nullable text, expected=nullable text, Result=text]}}),
    ExpandRows = Table.ExpandTableColumn(GroupRows, "t", {"Date Logged", "Job#", "audit action", "StartDate", "EndDate", "Input time as time type", "WhoChangedIt", "Analysis", "TotalDurationInStatus", "expected", "Result"}, {"Date Logged", "Job#.1", "audit action", "StartDate", "EndDate", "Input time as time type", "WhoChangedIt", "Analysis", "TotalDurationInStatus", "expected", "Result"})
in
    ExpandRows

 

- group your data, select "all rows"

- add an index from 0 to the nested table

- use it to obtain a range of 2 values and combine those strings

 

with this result

m_dekorte_0-1698768077741.png

I hope this is helpful

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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