Как превратить отношение «многие» на основе строк в макет на основе «одного» столбца

587
jolesexcel

Простите за мой английский. Я ищу метод преобразования данных для набора продуктов. У меня есть набор данных, в котором атрибуты перечислены в строках, и я хочу, чтобы эти атрибуты были заголовками столбцов, ссылающимися на значения и которые соответствуют этим атрибутам и продуктам, с которыми они связаны. Мой лучший пример будет следующим (для одного продукта):

до

Должен быть преобразован в:

после

Существуют тысячи отдельных «номеров деталей», поэтому простая транспонирование не обрезает их…

2
Я думаю, что слово, которое вы ищете, это «транспонировать» - посмотрите, поможет ли это вам. Raystafarian 9 лет назад 0
Транспонирование, к сожалению, нежизнеспособно, не каждый продукт будет соответствовать всем атрибутам в столбце B. Надеюсь, это имеет смысл. jolesexcel 9 лет назад 0
Транспонирование, безусловно, сработает, если я пойму вашу структуру данных. Raystafarian 9 лет назад 0
Извините, я считаю, что не правильно сформулировал свой ответ. Однако @Iszi предоставил метод, который работал. Спасибо за ваш вклад! jolesexcel 9 лет назад 0

1 ответ на вопрос

1
Iszi

This is a bit hacky, but it should work, if my "Assumptions & Interpretation" is correct.


Assumptions & Interpretation

Assumption 1: Your Part Numbers are all unique, and your AttributeIdentifiers are all exactly the same for the attributes you want to have represented in each column, across all parts.

Assumption 2: AttributeIdentifiers are unique within each part - that is, there will never be two lines having both the same AttributeIdentifier and the same Part Number.

Assumption 3: Original data has headers at row 1, and data is populated continuously, beginning at row 2.

Assumption 4: Original data is laid out similar to screenshots provided. "Part Numbers" are in column A, and "AttributeIdentifiers" are in column B, "Values" are in column C, and there is no other data on the sheet relevant to this problem.

Interpretation: You want the Part Numbers to remain in column A, and all attributes for that part listed on one row under headings according to their AttributeIdentifier.


Solution

  1. Create a new sheet in the same workbook.
  2. Name the first sheet Old Data, and the second sheet New Report.
  3. Copy 'Old Data'!A:A to 'New Report'!A:A.
  4. Perform "Remove Duplicates on 'New Report'!A:A.
  5. Copy 'Old Data'!B:B to 'New Report'!B:B.
  6. Perform "Remove Duplicates" on 'New Report'!B:B.
    • Make sure you do not expand the selection beyond this column for this operation.
  7. Delete 'New Report'!B1, and shift the remaining cells in that column up.
  8. Select all cells that have data within 'New Report'!B:B. COPY those cells, and use "Paste Special" and "Transpose" to paste them starting at 'New Report'!C1.
  9. Delete 'New Report'!B:B. Make sure 'New Report'!C:C shifts over to take its place.
  10. Add a new column to the left of 'Old Data'!A:A.
    • Note: This will shift all columns to the right, so that "Part Number" will be in column B and so on.
    • (Optional) Set 'Old Data'!A1 to UID.
  11. Set 'Old Data'!A2 to =CONCATENATE(B2,C2).
  12. Copy 'Old Data'!A2 down the entire column, until the end of the data set.
  13. Set 'New Report'!B2 to: =IFERROR(VLOOKUP(CONCATENATE($A2,B$1),'Old Data'!$A:$D,4,FALSE),"").
  14. Copy 'New Report'!B2 down the rest of the column, until the end of the data set.
  15. Copy all cells in 'New Report'!B:B, starting with 'New Report'!B2 and ending at the bottom of the data set, across to the remaining columns on the right.
  16. Select the entire 'New Report' sheet. Copy it and paste it in-place "As Values", to lock in the data.
  17. (Optional) Delete 'Old Data'!A:A.

Explanation of Step 14

The formula, in short, searches 'Old Data' for an appropriate value to place in the cell according to the matching "Part Number" and "AttributeIdentifier". If none is found, it will leave the cell blank.


Note: I have not personally tested this solution for your use case. However, I'm familiar enough with the steps involved to be reasonably confident that it should work for you with little need for modification. Please let me know if you encounter any errors.

Это сработало отлично, я изменил формулу на `= IFERROR (VLOOKUP (CONCATENATE ($ A2, B $ 1), 'Старые данные'! $ A: $ D, 4, FALSE)," ")` для ссылки на сдвиг данных добавив дополнительный столбец в Old Data. Большое спасибо! jolesexcel 9 лет назад 0
@jolesexcel Хороший вопрос. Извините, что пропустил это. Рад, что это сработало. Iszi 9 лет назад 0

Похожие вопросы