Forum Discussion

romovaro's avatar
romovaro
Responsive Resident
8 months ago
Solved

Merge rows in one and transform field

HI all Currently we have an excel file with customer details and a CUID with a unique number. CID is unique for the whole customer What I need is from that file to create a table where we keep   ...
  • CPCARDOSO's avatar
    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:

    1. Open Power Query in Excel or Power BI.
    2. Paste this code into Advanced Editor.
    3. Adjust:
      • The table name (Table1) to match your actual table.
      • Column names if they differ.
    4. 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.