Record consolidation

tigerzen

Board Regular
Joined
Mar 8, 2023
Messages
165
Office Version
  1. 365
Platform
  1. Windows
I have the following situation. Information is recorded in separate rows which needs to be consolidated into a single row so that a single letter detailing each activity can be generated. The spreadsheet shows the current situation, row 9 and below shows the required output. Note, the person I'm helping is not familiar with Power Query so I'm seeking a formula based approach if possible. Next choice would be a macro if it's simple enough to adapt to the actual data.

Sample 2.xlsx
ABCDEFGHIJKLM
1NameFacultyWork completedHoursCost Centre
2SamMedicineLecture2Nursing
3SamArtsTutorial3Admin
4JackPsychologyLecture1Admin
5JackArtsTutorial4General
6JackArtsTutorial3General
7
8
9NameFacultyWork completedHoursCost CentreFacultyWork completedHoursCost CentreFacultyWork completedHoursCost Centre
10SamMedicineLecture2NursingArtsTutorial3Admin
11JackPsychologyLecture1AdminArtsTutorial4GeneralArtsTutorial3General
Sheet1
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try this

Book1
ABCDEFGHIJKLMN
1NameFacultyWork completedHoursCost Centre
2SamMedicineLecture2Nursing
3SamArtsTutorial3Admin
4JackPsychologyLecture1Admin
5JackArtsTutorial4General
6JackArtsTutorial3General
7
8
9NameFacultyWork completedHoursCost CentreFacultyWork completedHoursCost CentreFacultyWork completedHoursCost Centre
10SamMedicineLecture2NursingArtsTutorial3Admin
11JackPsychologyLecture1AdminArtsTutorial4GeneralArtsTutorial3General
12
13
Sheet1
Cell Formulas
RangeFormula
A10:M11A10=IFERROR(DROP(REDUCE("",UNIQUE(A2:A6),LAMBDA(a,b,VSTACK(a,HSTACK(b,TOROW(FILTER(B2:E6,(A2:A6=b),"")))))),1),"")
Dynamic array formulas.
 
Upvote 0
Hi
a VBA Option
VBA Code:
Sub test()
Dim a
Dim i&
a = Cells(1, 1).CurrentRegion
With CreateObject("scripting.dictionary")
    For i = 1 To UBound(a)
        If Not .Exists(a(i, 1)) Then
        .Add a(i, 1), a(i, 2) & "|" & a(i, 3) & "|" & a(i, 4) & "|" & a(i, 5) & "|"
            If i = 1 Then .Item(a(1, 1)) = ""
        Else
            .Item(a(1, 1)) = .Item(a(1, 1)) & a(1, 2) & "|" & a(1, 3) & "|" & a(1, 4) & "|" & a(1, 5) & "|"
            .Item(a(i, 1)) = .Item(a(i, 1)) & a(i, 2) & "|" & a(i, 3) & "|" & a(i, 4) & "|" & a(i, 5) & "|"
        End If
    Next
Cells(12, 1).Resize(.Count, 2) = Application.Index(Application.Transpose(Array(.keys, .items)), 0, 0)
Cells(12, 2).Resize(.Count).TextToColumns Cells(12, 2), 1, , , , , , , True, "|"
End With
End Sub
 
Upvote 0
With Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    cType = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Faculty", type text}, {"Work completed", type text}, {"Hours", type text}, {"Cost Centre", type text}}),
    unPiv = Table.UnpivotOtherColumns(cType, {"Name"}, "Attribute", "Value"),
    cols = Table.FromList(List.Zip({unPiv[Attribute],Table.AddIndexColumn(unPiv, "Index", 1, 1, Int64.Type)[Index]}), Splitter.SplitByNothing(),null,null),
    ext = Table.ToList(Table.TransformColumns(cols, {"Column1", each Text.Combine(List.Transform(_, Text.From)), type text})),
    grp = Table.Group(unPiv, {"Name"}, {{"Count", each Text.Combine([Value],"|")}}),
    xList =  List.Max(Table.AddColumn(grp, "Custom", each List.Count(Text.PositionOfAny([Count], {"|"}, Occurrence.All)))[Custom])+1,  
    Split = Table.SplitColumn(grp, "Count", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), List.Range(ext,0,xList))
in
    Split



Book1
ABCDEFGHIJKLM
1NameFacultyWork completedHoursCost Centre
2SamMedicineLecture2Nursing
3SamArtsTutorial3Admin
4JackPsychologyLecture1Admin
5JackArtsTutorial4General
6JackArtsTutorial3General
7
8
9
10NameFaculty1Work completed2Hours3Cost Centre4Faculty5Work completed6Hours7Cost Centre8Faculty9Work completed10Hours11Cost Centre12
11SamMedicineLecture2NursingArtsTutorial3Admin
12JackPsychologyLecture1AdminArtsTutorial4GeneralArtsTutorial3General
Sheet1
 
Upvote 0
Another formula option
Excel Formula:
=LET(u,UNIQUE(FILTER(A2:A8,A2:A8<>"")),m,MAX(COUNTIFS(A2:A8,u)),DROP(REDUCE("",u,LAMBDA(x,y,VSTACK(x,HSTACK(y,EXPAND(TOROW(FILTER(B2:E8,A2:A8=y,"")),,m*4,""))))),1))
 
Upvote 0
Thanks so much everyone and I really appreciate your responses. In this case it's great to have different options because I'm trying to educate a young employee about how to solve data issues using Excel. The formula based solutions are very clever but I'm finding them testing as I'm more familiar with Excel 2019 but the new dynamic array formulae are terrific, even so, teaching them to someone with limited Excel skills will be challenging.

A couple of questions, can the formula based solutions be modified easily so that if information is added to the original data (eg employee Sam does more work and is added to the original list) the resultant arrays are automatically updated?

Mohadin, will your macro work if there are more fields than what I've provided in the sample data?
 
Upvote 0
Hi
And thank you
will your macro work if there are more fields than what I've provided in the sample data?
If you mean more row and employee the answer is yes
For more columns need some amendment.
let me know if you need any
Best regards
 
Upvote 0
A couple of questions, can the formula based solutions be modified easily so that if information is added to the original data (eg employee Sam does more work and is added to the original list) the resultant arrays are automatically updated?
The formula I provided already does that. :)
Fluff.xlsm
ABCDEFGHIJKLMNOPQ
1NameFacultyWork completedHoursCost Centre
2SamMedicineLecture2Nursing
3SamArtsTutorial3Admin
4JackPsychologyLecture1Admin
5JackArtsTutorial4General
6JackArtsTutorial3General
7JackArtsTutorial1Admin
8
9
10
11SamMedicineLecture2NursingArtsTutorial3Admin
12JackPsychologyLecture1AdminArtsTutorial4GeneralArtsTutorial3GeneralArtsTutorial1Admin
Data
Cell Formulas
RangeFormula
A11:Q12A11=LET(u,UNIQUE(FILTER(A2:A8,A2:A8<>"")),m,MAX(COUNTIFS(A2:A8,u)),DROP(REDUCE("",u,LAMBDA(x,y,VSTACK(x,HSTACK(y,EXPAND(TOROW(FILTER(B2:E8,A2:A8=y,"")),,m*4,""))))),1))
Dynamic array formulas.
 
Upvote 0
The formula I provided already does that. :)
Fluff.xlsm
ABCDEFGHIJKLMNOPQ
1NameFacultyWork completedHoursCost Centre
2SamMedicineLecture2Nursing
3SamArtsTutorial3Admin
4JackPsychologyLecture1Admin
5JackArtsTutorial4General
6JackArtsTutorial3General
7JackArtsTutorial1Admin
8
9
10
11SamMedicineLecture2NursingArtsTutorial3Admin
12JackPsychologyLecture1AdminArtsTutorial4GeneralArtsTutorial3GeneralArtsTutorial1Admin
Data
Cell Formulas
RangeFormula
A11:Q12A11=LET(u,UNIQUE(FILTER(A2:A8,A2:A8<>"")),m,MAX(COUNTIFS(A2:A8,u)),DROP(REDUCE("",u,LAMBDA(x,y,VSTACK(x,HSTACK(y,EXPAND(TOROW(FILTER(B2:E8,A2:A8=y,"")),,m*4,""))))),1))
Dynamic array formulas.
Hi Fluff,

It only adds data up to and including row 8, once more data is added, eg row 9 the output table is not updated.
 
Upvote 0
With Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    cType = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Faculty", type text}, {"Work completed", type text}, {"Hours", type text}, {"Cost Centre", type text}}),
    unPiv = Table.UnpivotOtherColumns(cType, {"Name"}, "Attribute", "Value"),
    cols = Table.FromList(List.Zip({unPiv[Attribute],Table.AddIndexColumn(unPiv, "Index", 1, 1, Int64.Type)[Index]}), Splitter.SplitByNothing(),null,null),
    ext = Table.ToList(Table.TransformColumns(cols, {"Column1", each Text.Combine(List.Transform(_, Text.From)), type text})),
    grp = Table.Group(unPiv, {"Name"}, {{"Count", each Text.Combine([Value],"|")}}),
    xList =  List.Max(Table.AddColumn(grp, "Custom", each List.Count(Text.PositionOfAny([Count], {"|"}, Occurrence.All)))[Custom])+1, 
    Split = Table.SplitColumn(grp, "Count", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), List.Range(ext,0,xList))
in
    Split



Book1
ABCDEFGHIJKLM
1NameFacultyWork completedHoursCost Centre
2SamMedicineLecture2Nursing
3SamArtsTutorial3Admin
4JackPsychologyLecture1Admin
5JackArtsTutorial4General
6JackArtsTutorial3General
7
8
9
10NameFaculty1Work completed2Hours3Cost Centre4Faculty5Work completed6Hours7Cost Centre8Faculty9Work completed10Hours11Cost Centre12
11SamMedicineLecture2NursingArtsTutorial3Admin
12JackPsychologyLecture1AdminArtsTutorial4GeneralArtsTutorial3General
Sheet1
another finish to your first three steps:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    tcn = Table.ColumnNames(Source),
    cType = Table.TransformColumnTypes(Source,List.Zip({tcn, List.Repeat({type text}, List.Count(tcn) )})),
    unPiv = Table.UnpivotOtherColumns(cType, {"Name"}, "Attribute", "Value"),
    Group = Table.Group(unPiv, {"Name"}, {{"All", each Table.CombineColumns(Table.TransformColumns(Table.AddIndexColumn(_, "Index",4),{"Index", (x)=> 
        Number.RoundDown(x/4)}), {"Attribute", "Index"}, (y)=> y{0} & "." & Text.From(y{1}), "ColNames")  }}),
    Expand = Table.ExpandTableColumn(Group, "All", {"Value", "ColNames"}),
    Pivot = Table.Pivot(Expand, List.Distinct(Expand[ColNames]), "ColNames", "Value")
in
    Pivot
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top