简体   繁体   English

使用 LEFT function 在数字不能很好地处理溢出的 arrays 之前提取所有内容

[英]Using the LEFT function to extract everything before a number doesn't work well with spilled arrays

I am currently trying to extract the prefix of a store ID to be able to then generate a list of stores with only that prefix.我目前正在尝试提取商店 ID 的前缀,以便能够生成仅具有该前缀的商店列表。

Cell D1 has that formula to extract the unique prefix:单元格 D1 具有提取唯一前缀的公式:

=TRANSPOSE(UNIQUE(LEFT(C2#, MIN(FIND({0,1,2,3,4,5,6,7,8,9},C2#&"0123456789"))-1)))

Cell C2 has that formula to extract the unique store ids from another sheet:单元格 C2 具有从另一张表中提取唯一商店 ID 的公式:

=UNIQUE(INDEX('Male Shoes',A1#,,6))

The problem is that the formula in D1 only returns the first two characters from all the unique prefixes instead of using the correct value for each prefixes.问题是 D1 中的公式只返回所有唯一前缀的前两个字符,而不是为每个前缀使用正确的值。

I have setup in column I the same formula as in D1 without the TRANSPOSE() and UNIQUE() functions and remove the # to see if that would return the correct value.我在 I 列中设置了与 D1 中相同的公式,但没有 TRANSPOSE() 和 UNIQUE() 函数,并删除 # 以查看是否会返回正确的值。 I dragged it down the length of the C column.我将它拖到 C 列的长度上。

=LEFT(C2, MIN(FIND({0,1,2,3,4,5,6,7,8,9},C2&"0123456789"))-1)

In Cell J2 I put the same formula has I2 but kept the # as a control.在单元格 J2 中,我将相同的公式放入 I2,但保留 # 作为控件。

=LEFT(C2#, MIN(FIND({0,1,2,3,4,5,6,7,8,9},C2#&"0123456789"))-1)

I believe the MIN() function is returning the minimum for the entire array and not for each row.我相信 MIN() function 返回整个数组的最小值,而不是每一行。 I haven't found how to mitigated that problem anywhere online.我还没有找到如何在网上任何地方缓解这个问题。

In my sample data that is not a problem since all the columns in D through G gave me the lists I was expecting but as more countries get added I might end up with duplicate country prefix.在我的示例数据中,这不是问题,因为 D 到 G 中的所有列都给了我期望的列表,但是随着更多国家的添加,我最终可能会得到重复的国家前缀。 (ie: If the prefixes get shortened to 2 characters - Germany=GE and Georgia=GE) (即:如果前缀缩短为 2 个字符 - Germany=GE 和 Georgia=GE)

样品表数据

If it is always 2 or three a simple IF instead of FIND will work:如果它总是 2 或 3,那么一个简单的IF而不是 FIND 将起作用:

=TRANSPOSE(UNIQUE(LEFT(C2#,IF(ISNUMBER(--MID(C2#,3,1)),2,3))))

在此处输入图像描述

Edit:编辑:

If there is only one time that it switches from alpha to numeric we can use:如果只有一次它从字母切换到数字,我们可以使用:

=TRANSPOSE(UNIQUE(LEFT(C2#,MMULT(ISNUMBER(--MID(C2#,SEQUENCE(,MAX(LEN(C2#))),1))*ISERROR(--MID("A"&C2#,SEQUENCE(,MAX(LEN(C2#))),1)),SEQUENCE(MAX(LEN(C2#))))-1)))

This does not care how many characters are in the string, only that there is only 1 time that it switches from alpha to numeric.这不关心字符串中有多少个字符,只关心它从字母切换到数字只有 1 次。 So ABDEFGHTEV4567 will work but A3D4 will not.所以ABDEFGHTEV4567可以工作,但A3D4不行。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM