如何从子SKU中获取最低数量并将该数字设置为父SKU或添加。

huangapple go评论61阅读模式
英文:

How to Take Lowest Quantity from Child SKUs and set that number to Parent SKU or add

问题

我目前正在使用=IFERROR(MAP(A2:A1301,LAMBDA(r,MIN(FILTER(B2:B1301,LEFT(A2:A1301,9)=r&":")))),B2:B1301)来查找子SKU的最低数量,并将其应用于父SKU。

然而,还有一些其他情况和条件我需要考虑。

BEFORE FORMULA:

SKU Quantity
26013004 1
26013004:26013004F 0
26013004:26013004H 0
26013004:26013004R 1
26015002 0
31003002:31003002B 1
31003002:31003002T 1
31004001 0
31004002 0
31004002:31004002A 32
31004002:31004002B 48
31005001 1
31005001:31005001A 3
31005001:31005001B 6
31005002 7
31005002:31005002A 5
31005002:31005002B 4
31005003 7
31005003:31005003A 8
31005003:31005003B 4

Scenarios:

父SKU = 0
子SKU 1 = 0
子SKU 2 = 1
-------------
父SKU -> 0
没有足够的零件组成完整产品,不会添加到父SKU。

~~~~~~~~~~~~~~~~~~~
父SKU = 0
子SKU 1 = 1
子SKU 2 = 1
-------------
父SKU -> 1
有足够的零件组成完整的部件,可以添加到父SKU。

~~~~~~~~~~~~~~~~~~~
父SKU = 0
子SKU 1 = 32
子SKU 2 = 48
-------------
父SKU -> 32
其他子SKU多出的部分,但从技术上只能制造32个完整的父SKU。

~~~~~~~~~~~~~~~~~~~
父SKU = 1
子SKU 1 = 3
子SKU 2 = 6
-------------
父SKU -> 4
已经存在1个完整的父SKU,3个子SKU可以制成一个完整的父SKU,添加3+1以获得总共4个。

~~~~~~~~~~~~~~~~~~~
父SKU = 7
子SKU 1 = 5
子SKU 2 = 4
-------------
父SKU -> 7
数据库中可能存在差异,但如果父SKU最终高于每个子SKU,保持不变。

如何将所有这些情况应用到一个公式中?我正在使用Excel 365。

英文:

I am currently using =IFERROR(MAP(A2:A1301,LAMBDA(r,MIN(FILTER(B2:B1301,LEFT(A2:A1301,9)=r&":")))),B2:B1301) to find child SKUs' lowest number and applying it to the parent SKU.

However there are some other scenarios and criterias I needed.

BEFORE FORMULA:

SKU Quantity
26013004 1
26013004:26013004F 0
26013004:26013004H 0
26013004:26013004R 1
26015002 0
31003002:31003002B 1
31003002:31003002T 1
31004001 0
31004002 0
31004002:31004002A 32
31004002:31004002B 48
31005001 1
31005001:31005001A 3
31005001:31005001B 6
31005002 7
31005002:31005002A 5
31005002:31005002B 4
31005003 7
31005003:31005003A 8
31005003:31005003B 4

Scenarios:

Parent Sku = 0
Child Sku 1 = 0
Child Sku 2 = 1
-------------
Parent Sku -> 0
Not enough parts to be a full item, none is added to parent.

~~~~~~~~~~~~~~~~~~~
Parent Sku = 0
Child Sku 1 = 1
Child Sku 2 = 1
-------------
Parent Sku -> 1
Enough for a full part to be added to parent SKU

~~~~~~~~~~~~~~~~~~~
Parent Sku = 0
Child Sku 1 = 32
Child Sku 2 = 48
-------------
Parent Sku -> 32
Extra of other child sku, but technically can only make 32 full items of the parent SKU

~~~~~~~~~~~~~~~~~~~
Parent Sku = 1
Child Sku 1 = 3
Child Sku 2 = 6
-------------
Parent Sku -> 4
1 Full Parent Sku already exists, 3 of child skus can be made into a full parent sku, add 3+1 to make 4 total

~~~~~~~~~~~~~~~~~~~
Parent Sku = 7
Child Sku 1 = 5
Child Sku 2 = 4
-------------
Parent Sku -> 7
Possible discrepancy in database but if parent SKU ends up being higher than every child sku, stays the same.

How could I apply all these scenarios into 1 formula at most? I'm using excel 365.

答案1

得分: 1

以下是翻译后的代码部分:

=LET(sku, A2:A21, qty, B2:B21, isChild, ISNUMBER(SEARCH("":"",sku)),
 children, FILTER(sku, isChild), parent, FILTER(sku, NOT(isChild)),
 npQty, MAP(parent, LAMBDA(p, LET(pQty, XLOOKUP(p, sku, qty),
  cQty, FILTER(qty, (ISNUMBER(SEARCH(p,sku))) * (isChild),""),
   IF(@cQty="", pQty, IF(pQty > MIN(cQty), pQty, pQty + MIN(cQty)))))),
 HSTACK(parent, npQty))

如果你需要返回每个输入数据的新数量(如果更改的话,否则保持不变),你可以使用以下公式代替:

=LET(skus, A2:A21, qtys, B2:B21, isChild, ISNUMBER(SEARCH("":"",skus)),
 MAP(skus, qtys, LAMBDA(sku,qty,
 IF(@FILTER(qtys, (skus=sku) * NOT(isChild),"")<>"",
  LET(cQty, FILTER(qtys, (ISNUMBER(SEARCH(sku,skus))) * (isChild),""),
   IF(@cQty="", qty, IF(qty > MIN(cQty), qty, qty + MIN(cQty)))), qty))))

请注意,我已将双引号中的内容保持不变,因为它们似乎是代码中的特殊字符。

英文:

Following the logic mentioned in the comment section of the question, we can apply it as follows:

=LET(sku, A2:A21, qty, B2:B21, isChild, ISNUMBER(SEARCH(&quot;:&quot;,sku)),
 children, FILTER(sku, isChild), parent, FILTER(sku, NOT(isChild)),
 npQty, MAP(parent, LAMBDA(p, LET(pQty, XLOOKUP(p, sku, qty),
  cQty, FILTER(qty, (ISNUMBER(SEARCH(p,sku))) * (isChild),&quot;&quot;),
   IF(@cQty=&quot;&quot;, pQty, IF(pQty &gt; MIN(cQty), pQty, pQty + MIN(cQty)))))),
 HSTACK(parent, npQty))

Here is the output:
如何从子SKU中获取最低数量并将该数字设置为父SKU或添加。

Highlighted in yellow a value that was changed in order to have children (it seems a mistake from the input data). In green a value that doesn't have children.

The name isChild, identifies rows that are children by finding the : token. Based on that we can identify parent and children via FILTER. We use MAP to iterate over each parent(p) and implement the logic for the new parent quantity (npQty). The name cQty, has the quantities of the children for a given parent (p). We cover the case, for a given parent (p) there are no children, as in the case of 31004001. For this case the FILTER function returns &quot;&quot; so the parent quantity remains the same. If there are children, we build the logic to modify the quantity.

If you want to return just thew new quantities (in case it changes, otherwise the same quantity) for each input data, you can use the following formula instead:

=LET(skus, A2:A21, qtys, B2:B21, isChild, ISNUMBER(SEARCH(&quot;:&quot;,skus)),
 MAP(skus, qtys, LAMBDA(sku,qty,
 IF(@FILTER(qtys, (skus=sku) * NOT(isChild),&quot;&quot;)&lt;&gt;&quot;&quot;,
  LET(cQty, FILTER(qtys, (ISNUMBER(SEARCH(sku,skus))) * (isChild),&quot;&quot;),
   IF(@cQty=&quot;&quot;, qty, IF(qty &gt; MIN(cQty), qty, qty + MIN(cQty)))), qty))))

huangapple
  • 本文由 发表于 2023年2月9日 03:15:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75390688.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定