Looking for a way to sum multiple text strings within a single cell to a number value

Nalfen

New Member
Joined
Mar 19, 2019
Messages
3
Hope someone can help me.

I have single cells containing values separated by commas. Something like this: XFF,ONG,S,HP

I want to be able to lookup occurence of a string and then get a sum of all strings in that cell based on corresponding values found in a table:


DTX5
XFF4
ONG3
S1
HP4
INV1
GENERIC0

<tbody>
</tbody>

<colgroup><col width="64" span="2" style="width:48pt"></colgroup><tbody>
</tbody>
Based on the above (XFF,ONG,S,HP) i would want it to return the sum of all those which would be 12

Is that possible?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
are you able to use PowerQuery (Get&Transform)?

ItemsValueSumResult
DTX
5​
XFF,GENERIC,HP
8​
XFF
4​
ONG
3​
S
1​
HP
4​
INV
1​
GENERIC
0​

SumResult
ONG,INV,DTX
9​
 
Last edited:
Upvote 0
DTX5
XFF4
ONG3
S1
HP4
INV1
GENERIC0

<tbody>
</tbody>

<tbody>
</tbody>
Is this table complete? I am worried about smaller codes being embedded within longer codes (with the table above, that is not a problem which is why I want to know if the table could contain more codes).
 
Upvote 0
I cna use Get&Transform, never used it so i would have to look it up but i do have that option.

The table contains 20 rows and 2 columns only
 
Upvote 0
Welcome to the Board.

There may be neater ways, such as PowerQuery or a UDF, but here's one way:

ABCDEF
1CodeValueStringSum
2DTX5XFF,ONG,S,HP12
3XFF4
4ONG3
5S1
6HP4
7INV1
8GENERIC0

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet5


Array Formulas
CellFormula
E2{=SUM(SUMIF($A$2:$A$8,TRIM(MID(SUBSTITUTE(D2,",",REPT(" ",100)),(ROW(INDIRECT("1:10"))-1)*100+1,100)),$B$2:$B$8))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>




This should work for up to 10 elements in a cell.
 
Upvote 0
I cna use Get&Transform, never used it so i would have to look it up but i do have that option.

The table contains 20 rows and 2 columns only

for future to test :)

ItemsValueSumResult
DTX
5​
ONG,ABC,ZZX,QWERTY
28​
XFF
4​
ONG
3​
S
1​
HP
4​
INV
1​
GENERIC
0​
S
10​
ABC
11​
ZZX
12​
AA
5​
CC
4​
XX
3​
QWERTY
2​

Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    SplitR = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Sum", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Sum"),
    Merge = Table.NestedJoin(SplitR,{"Sum"},Table1,{"Items"},"Table1",JoinKind.LeftOuter),
    Expand = Table.ExpandTableColumn(Merge, "Table1", {"Value"}, {"Value"}),
    Sum = List.Sum(Expand[Value]),
    Convert = #table(1, {{Sum}}),
    Ren = Table.RenameColumns(Convert,{{"Column1", "Result"}})
in
    Ren[/SIZE]

you can add more "codes" even duplicated
 
Last edited:
Upvote 0
Welcome to the Board.

Sheet5


Array Formulas
CellFormula
E2{=SUM(SUMIF($A$2:$A$8,TRIM(MID(SUBSTITUTE(D2,",",REPT(" ",100)),(ROW(INDIRECT("1:10"))-1)*100+1,100)),$B$2:$B$8))}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>




This should work for up to 10 elements in a cell.

Tested this and it works great. I will still lookup the PowerQuery as it looks like a cleaner way to do those things but i appreciate the help.
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

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