Forum Discussion
Merge rows in one and transform field
- 8 months ago
Hello romovaro ...
It is possible to solve this using Power Query in Excel or Power BI (Microsoft Fabric), by creating a transformation logic to consolidate the rows according to your rule. I will explain how to do it. Try this:
--let
// 1. Source: adjust to your table name
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],// 2. Change column types (adjust as needed)
ChangedTypes = Table.TransformColumnTypes(Source,
{
{"Name", type text},
{"CID", type text},
{"Client", type text},
{"CUID", type text},
{"Country Long Name", type text},
{"Project Type", type text},
{"Project Scope", type text},
{"Contract Signing Date", type date},
{"LOA Signing Date", type date},
{"Implementation Window End Date", type date},
{"Planned # of EEs", Int64.Type},
{"Segment", type text}
}
),// 3. Filter Country Projects
CountryProjects = Table.SelectRows(ChangedTypes, each [Project Type] = "Country Project"),// 4. Filter Integration Projects
IntegrationProjects = Table.SelectRows(ChangedTypes, each [Project Type] = "Integration Project"),// 5. Group by CID and keep the row with the earliest Contract Signing Date
Grouped = Table.Group(IntegrationProjects, {"CID"},
{
{"EarliestDate", each Table.Sort(_, {{"Contract Signing Date", Order.Ascending}}){0}, type table}
}
),// 6. Expand the selected row
Expanded = Table.ExpandTableColumn(Grouped, "EarliestDate",
{"Name", "CID", "Client", "CUID", "Country Long Name", "Project Type", "Project Scope",
"Contract Signing Date", "LOA Signing Date", "Implementation Window End Date",
"Planned # of EEs", "Segment"}
),// 7. Adjust CUID to end with "i"
AdjustedCUID = Table.TransformColumns(Expanded,
{
{"CUID", each Text.BeforeDelimiter(_, "-") & "i", type text}
}
),// 8. Combine Country Projects + Adjusted Integration Projects
FinalResult = Table.Combine({CountryProjects, AdjustedCUID})
in
FinalResult--
Hoe to use:
- Open Power Query in Excel or Power BI.
- Paste this code into Advanced Editor.
- Adjust:
- The table name (Table1) to match your actual table.
- Column names if they differ.
- Click Done and load the data.
I think this code will help you.
Don’t forget the kudos, it costs you nothing and we help each other. Cheers.
Please show an example of the result you want so we know exactly what data you want to keep and how you want it arranged.
Regards
Phil
- romovaro8 months agoResponsive Resident
HI Philip
see below table sample:
Name CID Customer CUID Country Long Name Project Type Project Scope Contract Signed Date LOA Signature Date Kick Off Date Status Actual/Schedule Go Live Renor SA - BR - 1001141BR01
1001141 Renor SA 1001141BR01 Brazil Country Project Payroll 3/31/2025 On hold Renor SA - BR - 1001141BR01i
1001141 RenorSA 1001141BR01-wd Brazil Integration Project Integration WD 3/31/2025 On hold 12/31/2025 Renor SA - BR - 1001141BR01i 1001141 Renor SA 1001141BR01-sf Brazil Integration Project Integration SF 5/30/2026 On hold 5/30/2026 AMOR SA - BR - 1001141BR01 1001142 Amor SA 1001142BR01 Brazil Country Project Payroll 5/31/2024 On hold AMOR SA - BR - 1001141BR02
1001142 Amor SA 1001142BR01-wd Brazil Integration Project Integration WD 3/31/2025 Live 3/31/2025 AMOR SA - BR - 1001141BR03 1001142 Amor SA 1001142BR01-or Brazil Integration Project Integration OR 5/30/2027 Under Implementation 3/31/2026 I started with a split: Integration and not integration
IsIntegration = IF (CONTAINSSTRING(OriginalPV[CUID],"-"),"Integration","Payroll")And because in my new table i just want the CUID finalizing with "-i" I have this formula:NormalizedCUID =IF(OriginalPV[IsIntegration] = "Integration", LEFT(OriginalPV[CUID], FIND("-", OriginalPV[CUID],1)-1) & "-i", OriginalPV[CUID])From the original file I can create a table showing only payroll:OnlyPayroll = FILTER(OriginalPV, OriginalPV[IsIntegration] = "Payroll")And the questions I have is for the Integration table.For the first customer I have 2 CUIDs. I just need to show the one with the closest "Actual/Schedule Go Live" vs today. (but future date...past dates not needed) In that case the WD with GLD 12/31/2025.RenorSA 1001141BR01-wd Renor SA 1001141BR01-sf I created a formula counting the days
Datesfromtoday =VAR Effective = OriginalPV[Actual/Schedule Go Live].[Date]RETURNIF(OriginalPV[IsIntegration] = "Integration",DATEDIFF(TODAY(), Effective, DAY),BLANK())And created an IntegrationFuturetable:IntegrationFuture =FILTER(OriginalPV,OriginalPV[IsIntegration] = "Integration" && OriginalPV[Actual/Schedule Go Live] > TODAY())Now I am trying to filter so I only get one row:MostRecentFuture =VAR FutureRows =FILTER(IntegrationFuture,IntegrationFuture[IsIntegration] = "Integration"&& NOT ISBLANK(IntegrationFuture[AbsDayDiff]))RETURNFILTER(ADDCOLUMNS(IntegrationFuture,"RankClosest",RANKX(FILTER(IntegrationFuture,[CID] = EARLIER([CID])),IntegrationFuture[AbsDayDiff],,ASC,Dense)),[RankClosest] = 1)But I am getting: The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.My last step would be merge both tables (Payroll only and Integration one)FINAL TABLE = NATURALLEFTOUTERJOIN(PayrollOnly,IntegrationFUture)Final table for the first customer:Name CID Customer CUID Country Long Name Project Type Project Scope Contract Signed Date LOA Signature Date Kick Off Date Status Actual/Schedule Go Live Renor SA - BR - 1001141BR01
1001141 Renor SA 1001141BR01 Brazil Country Project Payroll 3/31/2025 On hold Renor SA - BR - 1001141BR01i
1001141 RenorSA 1001141BR01-wd Brazil Integration Project Integration WD 3/31/2025 On hold 12/31/2025 vvv