简体   繁体   English

对 AZ 进行排序但保持产品/变体完整性

[英]Sort A-Z but keep Products/Variation Integrity

在此处输入图像描述 I am working on a price sheet that has products with variations to that product underneath.我正在制作一个价格表,其中包含与该产品不同的产品。 It has 15,000 rows and I would like to sort in alphabetical order.它有 15,000 行,我想按字母顺序排序。

However doing so breaks the product/variations, so you wont know what variations are with what product.但是这样做会破坏产品/变体,因此您不知道什么产品有什么变体。 I have color coded all the products as well as the variations.我对所有产品及其变体进行了颜色编码。

What I need is the Products to be sorted AZ, along with keeping the variations underneath it.我需要的是要按 AZ 排序的产品,并保留其下方的变体。

Sorting breaks the product/variation setup.排序会破坏产品/变体设置。

Using an excel formula, here is a possible approach.使用 excel 公式,这是一种可能的方法。 In cell D2 , put the following formula:在单元格D2中,输入以下公式:

=LET(rng, A2:B9, types, INDEX(rng,,1), names, INDEX(rng,,2),
  groups, SCAN("", names, LAMBDA(acc,name, IF(acc="",name,
    IF(XLOOKUP(name, names, types)="Product", name, acc)))),
 DROP(SORT(HSTACK(rng, groups), COLUMNS(rng)+1),,-1)
)

Here is the output:这是 output:

示例 excel 文件

groups name contains an array of the same number of rows of rng , having the product name for the product and its variation. groups name 包含相同行数的数组rng ,具有产品及其变体的产品名称。 Then we just need to sort by this intermediate column created the input range.然后我们只需要按这个创建输入范围的中间列进行排序。

Note : This solution assumes the first row always starts with a Product , not a Variation .注意:此解决方案假定第一行始终以Product而不是Variation开头。

Adding a helper column C is another alternative.添加辅助列C是另一种选择。 For example, put in C2 the following formula and drag it down:例如,将以下公式放入C2并向下拖动:

=IF(A2="Product", B2, C1)

then you can use this column for sorting.那么您可以使用此列进行排序。 This is exactly what the SCAN formula does, but generating the values programmatically.这正是SCAN公式所做的,但以编程方式生成值。

Make a new column in front of A (or wherever, doesn't really matter, visually is easiest imo): "Sort"在 A 前面创建一个新列(或任何地方,并不重要,视觉上最简单的 imo):“排序”

=If(B2 = "Product"; C2; A1+1)

Copy paste as Values and then sort descending.复制粘贴为值,然后降序排序。 You can delete/hide the A column after then.之后您可以删除/隐藏 A 列。 Making "keys" is the easiest way to sort/organize/check for doubles.制作“钥匙”是排序/组织/检查双打的最简单方法。

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

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