Filter Unique records with Adding and Concatenate from duplicate Rows

NiladriACN

New Member
Joined
Mar 27, 2019
Messages
3
Hi All,

This is my first post here and hope will get my answer here. I have a table with 3 columns, store, Weighting and matrix. I need the unique store list from the table but weighting and matrix columns should be added or concatenated before deleting the duplicate rows. Please find the below input and output table. Stored no is sorted as an order

Input Table

StoreWeightingMatrix
3010ABC>10
3015DEF = 15
3027CDE <= 22
2012ABC = 2
2010DEF = 25

<tbody>
</tbody>

Output Table
StoreweightingMatrix
3052 (10+15+27)ABC > 10;DEF =15 ;CDE <=22
2022 (12 +10)ABC = 2 ; DEF = 25

<tbody>
</tbody>

Is there any formula or code to solve this issue ? I have more than 10K rows so manually checking it's time consuming.

Please help!!

Regards,
Niladri

****** id="cke_pastebin" style="position: absolute; top: 322.667px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">
ABC>10

<tbody>
</tbody>
</body>
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
you can try PowerQuery (Get&Transform)

StoreWeightingMatrixStoreWeightingMatrix
30​
10​
ABC>10
30​
52​
ABC>10;DEF = 15;CDE <= 22
30​
15​
DEF = 15
20​
22​
ABC = 2;DEF = 25
30​
27​
CDE <= 22
20​
12​
ABC = 2
20​
10​
DEF = 25
Code:
[SIZE=1]
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"Store"}, {{"Weighting", each List.Sum([Weighting]), type number}, {"Count", each _, type table}}),
    ToList = Table.AddColumn(Group, "Matrix", each Table.Column([Count],"Matrix")),
    Extract = Table.TransformColumns(ToList, {"Matrix", each Text.Combine(List.Transform(_, Text.From), ";"), type text})
in
    Extract[/SIZE]
 
Last edited:
Upvote 0
Maybe this macro...

Code:
Sub aTest()
    Dim dic As Object, vData As Variant, i As Long
    Dim vAux As Variant, vKey As Variant, vResult As Variant
    
    Set dic = CreateObject("Scripting.Dictionary")
    dic.CompareMode = vbTextCompare
    
    'Assumes data in columns A:C, headers in row 1
    vData = Range("A2:C" & Cells(Rows.Count, "A").End(xlUp).Row)
    For i = LBound(vData, 1) To UBound(vData, 1)
        If dic.exists(vData(i, 1)) Then
            vAux = dic(vData(i, 1))
            vAux(0) = vAux(0) + vData(i, 2)
            vAux(1) = vAux(1) & ";" & vData(i, 3)
            dic(vData(i, 1)) = vAux
        Else
            dic(vData(i, 1)) = Array(vData(i, 2), vData(i, 3))
        End If
    Next i
    
    'Output in columns E:G
    Range("E1:G1") = Array("Store", "Weighting", "Matrix")
    vResult = Range("E2").Resize(dic.Count, 3)
    i = 0
    For Each vKey In dic.keys
        i = i + 1
        vResult(i, 1) = vKey
        vResult(i, 2) = dic(vKey)(0)
        vResult(i, 3) = dic(vKey)(1)
    Next vKey
    Range("E2").Resize(dic.Count, 3) = vResult
    Columns("E:G").AutoFit
End Sub

M.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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