how to sum value in delimeter on a single cell with date condition selected

pomzung125

New Member
Joined
Aug 27, 2023
Messages
3
Office Version
  1. 2021
Platform
  1. MacOS
  2. Mobile
Hi, Everyone

I would to sum stock count corresponding to sku number with the selected bank tranfer date as a condition.


Screen Shot 2566-08-28 at 10.21.30.png


If I select 10-May-23, it should represent sum stock with corresponding SKU number. Sometime there are 2 SKUs and quantity in a single cell separated with comma. The expected result will be like this




Screen Shot 2566-08-28 at 10.20.42.png
.

If I choose 17-may-23 as bank transfer date, it shall show like this.
Screen Shot 2566-08-28 at 10.20.46.png


I'm struggling with this problem. I don't really know how to deal with.
If anyone could help me, i'm so appreciated. :)


Thank you so much
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Power Query Solution
Book3
ABCDEFGHI
1transfer datechannelpricebegin dateend dateorder numbercustomer payment dateSKUQuantity
210-May-23Tiktok2,877.875-May-239-May-235772374602158260005/5/2023TK002-031
35772342507351920005/5/2023TK002-02, TK001-022,3
45772342419077550005/5/2023TK002-02, TK001-022, 3
55772342293448970005/5/2023TK002-02, TK001-022, 3
65772492578389060005/9/2023TK002-032
710/17/2023Tiktok463.6812-May-235772610854468010005/12/2023TK002-031
85772589557181010005/12/2023LM005-011
9
10
11transfer dateColumn1Sum
125/10/2023TK002-033
135/10/2023TK002-026
145/10/2023TK001-029
1510/17/2023TK002-031
1610/17/2023LM005-011
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Filled Down" = Table.FillDown(Source,{"transfer date", "channel", "price", "begin date", "end date"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Filled Down",{{"transfer date", type date}, {"channel", type text}, {"price", type number}, {"begin date", type datetime}, {"end date", type datetime}, {"order number", Int64.Type}, {"customer payment date", type datetime}, {"SKU", type text}, {"Quantity", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.FromColumns({Text.Split([SKU], ","),Text.Split([Quantity], ",")})),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Column1", "Column2"}, {"Column1", "Column2"}),
    #"Trimmed Text" = Table.TransformColumns(#"Expanded Custom",{{"Column1", Text.Trim, type text}, {"Column2", Text.Trim, type text}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Trimmed Text",{{"Column2", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"transfer date", "Column1"}, {{"Sum", each List.Sum([Column2]), type nullable number}})
in
    #"Grouped Rows"
 
Upvote 1
Power Query Solution
Book3
ABCDEFGHI
1transfer datechannelpricebegin dateend dateorder numbercustomer payment dateSKUQuantity
210-May-23Tiktok2,877.875-May-239-May-235772374602158260005/5/2023TK002-031
35772342507351920005/5/2023TK002-02, TK001-022,3
45772342419077550005/5/2023TK002-02, TK001-022, 3
55772342293448970005/5/2023TK002-02, TK001-022, 3
65772492578389060005/9/2023TK002-032
710/17/2023Tiktok463.6812-May-235772610854468010005/12/2023TK002-031
85772589557181010005/12/2023LM005-011
9
10
11transfer dateColumn1Sum
125/10/2023TK002-033
135/10/2023TK002-026
145/10/2023TK001-029
1510/17/2023TK002-031
1610/17/2023LM005-011
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Filled Down" = Table.FillDown(Source,{"transfer date", "channel", "price", "begin date", "end date"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Filled Down",{{"transfer date", type date}, {"channel", type text}, {"price", type number}, {"begin date", type datetime}, {"end date", type datetime}, {"order number", Int64.Type}, {"customer payment date", type datetime}, {"SKU", type text}, {"Quantity", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.FromColumns({Text.Split([SKU], ","),Text.Split([Quantity], ",")})),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Column1", "Column2"}, {"Column1", "Column2"}),
    #"Trimmed Text" = Table.TransformColumns(#"Expanded Custom",{{"Column1", Text.Trim, type text}, {"Column2", Text.Trim, type text}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Trimmed Text",{{"Column2", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"transfer date", "Column1"}, {{"Sum", each List.Sum([Column2]), type nullable number}})
in
    #"Grouped Rows"
You're so kind. I'm so appreciated with your solution. Thank you so much. :)

Anyway I'm still wondering about if there is no power query how we handle this kind of situation.
 
Upvote 0
Here a VBA solution which should work on a Mac.

VBA Code:
Sub jec()
 Dim ar, xp, sp, j As Long, jj As Long, jjj As Long, st As Long
 ar = Cells(1).CurrentRegion.Value2
 ReDim sq(UBound(ar), 3)
 
 For j = 2 To UBound(ar)
   st = IIf(ar(j, 1) > st, ar(j, 1), st)
   sp = Split(ar(j, 8), ", ")
   For jj = 0 To UBound(sp)
     For jjj = 0 To UBound(sq)
       xp = Val(Split(ar(j, 9), ", ")(jj))
       If sq(jjj, 3) = st & "|" & sp(jj) Then
         sq(jjj, 2) = sq(jjj, 2) + xp
         Exit For
       ElseIf sq(jjj, 0) = "" Then
         sq(jjj, 0) = st
         sq(jjj, 1) = sp(jj)
         sq(jjj, 2) = xp
         sq(jjj, 3) = st & "|" & sp(jj)
         Exit For
       End If
     Next
   Next
 Next
 
 Cells(23, 1).Resize(UBound(sq), 3) = sq
End Sub



Used this layout

Book1
ABCDEFGHIJ
1transfer datechannelpricebegin dateend dateorder numbercustomer payment dateSKUQuantity
210-5-2023Tiktok2877.8745051450555,77E+175-5-2023TK002-031
35,77E+175-5-2023TK002-02, TK001-022, 3
45,77E+175-5-2023TK002-02, TK001-022, 3
55,77E+175-5-2023TK002-02, TK001-022, 3
65,77E+175-9-2023TK002-032
717-10-2023Tiktok463.68450585,77E+175-12-2023TK002-031
85,77E+175-12-2023LM005-011
9
10
Sheet1
 
Upvote 1
Solution
Here a VBA solution which should work on a Mac.

VBA Code:
Sub jec()
 Dim ar, xp, sp, j As Long, jj As Long, jjj As Long, st As Long
 ar = Cells(1).CurrentRegion.Value2
 ReDim sq(UBound(ar), 3)
 
 For j = 2 To UBound(ar)
   st = IIf(ar(j, 1) > st, ar(j, 1), st)
   sp = Split(ar(j, 8), ", ")
   For jj = 0 To UBound(sp)
     For jjj = 0 To UBound(sq)
       xp = Val(Split(ar(j, 9), ", ")(jj))
       If sq(jjj, 3) = st & "|" & sp(jj) Then
         sq(jjj, 2) = sq(jjj, 2) + xp
         Exit For
       ElseIf sq(jjj, 0) = "" Then
         sq(jjj, 0) = st
         sq(jjj, 1) = sp(jj)
         sq(jjj, 2) = xp
         sq(jjj, 3) = st & "|" & sp(jj)
         Exit For
       End If
     Next
   Next
 Next
 
 Cells(23, 1).Resize(UBound(sq), 3) = sq
End Sub



Used this layout

Book1
ABCDEFGHIJ
1transfer datechannelpricebegin dateend dateorder numbercustomer payment dateSKUQuantity
210-5-2023Tiktok2877.8745051450555,77E+175-5-2023TK002-031
35,77E+175-5-2023TK002-02, TK001-022, 3
45,77E+175-5-2023TK002-02, TK001-022, 3
55,77E+175-5-2023TK002-02, TK001-022, 3
65,77E+175-9-2023TK002-032
717-10-2023Tiktok463.68450585,77E+175-12-2023TK002-031
85,77E+175-12-2023LM005-011
9
10
Sheet1
Thank you so much for your solution :)
It works like a charm on my MacOS. 🤩
 
Upvote 0
You're welcome. Cheers!
 
Upvote 0

Forum statistics

Threads
1,215,111
Messages
6,123,155
Members
449,098
Latest member
Doanvanhieu

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