我是数据透视表,Power Query,DAX公式等的新手,我想知道如何使用数据透视表,Power Query等获得所需的输出,或者只有使用VBA宏才能实现。
我正在使用Excel 2016。
在我在其他网站上问这个问题之前,我收到的唯一答案是对此example的引用,但是我在将表格转换为列出他们在此处给出的公式Table.FromRows( List.Split( Table1[Column1], 3) )
后才无法使用我。
这是我的输入表:
| DESCRIPTION | VALUE |
|-------------|--------|
| STAGE | 1 |
| ID | 0 |
| NAME | JFMSC |
| TYPE | MLRR |
| DFRUL | P1 |
| ADDR | 1001 |
| RRUL | P1 |
| SPRR | TRUE |
| ISGALW | FALSE |
| ISUTWD | FALSE |
| STAGE | 1 |
| ID | 2 |
| NAME | PLLSJS |
| TYPE | MLRR |
| DFRUL | P1 |
| STAGE | 1 |
| ID | 4 |
| NAME | AAAARR |
| TYPE | MLRR |
| DFRUL | R2 |
| ADDR | 3553 |
| RRUL | P1 |
| SPRR | FALSE |
| ISGALW | FALSE |
| ISUTWD | FALSE |
| ADDR | 66444 |
| RRUL | P1 |
| SPRR | FALSE |
| ISGALW | FALSE |
| ISUTWD | FALSE |
| ADDR | 890087 |
| RRUL | P1 |
| SPRR | FALSE |
| ISGALW | FALSE |
| ISUTWD | FALSE |
| STAGE | 1 |
| ID | 0 |
| NAME | PPROOA |
| TYPE | RRHN |
| DFRUL | P1 |
| ADDR | 7034 |
| RRUL | P1 |
| SPRR | FALSE |
| ISGALW | FALSE |
| ISUTWD | FALSE |
这是我想要获得的输出:
| STAGE | ID | NAME | TYPE | DFRUL | ADDR | RRUL |
|-------|----|--------|------|-------|--------|------|
| 1 | 0 | JFMSC | MLRR | P1 | 1001 | P1 |
| 1 | 2 | PLLSJS | MLRR | P1 | | |
| 1 | 4 | AAAARR | MLRR | R2 | 3553 | P1 |
| | | | | | 66444 | P1 |
| | | | | | 890087 | P1 |
| 1 | 0 | PPROOA | RRHN | P1 | 7034 | P1 |
更新
输入空格和一些其他未使用的文本,但要转换的字段相同。
+----------------------------+---------+
| DESCRIPTION | VALUE |
+----------------------------+---------+
| | |
| | |
| ..d 2019-03-07 17:35:52 | |
| KLAPW | #075286 |
| STAGE=1, ID=0, TYPE=MLRR | |
| | |
| | |
| STAGE | 1 |
| ID | 0 |
| NAME | NAME1 |
| TYPE | MLRR |
| DFRUL | P1 |
| ADDR | 8876 |
| RRUL | P1 |
| SPRR | TRUE |
| ISGALW | FALSE |
| ISUTWD | FALSE |
| | |
| | |
| Total count | 10 |
| | |
| There is together 1 report | |
| | |
| END_BLOCK | |
| | |
| | |
| ..d 2019-03-07 17:35:52 | |
| KLAPW | #075287 |
| STAGE=1, ID=1, TYPE=MLRR | |
| | |
| | |
| STAGE | 1 |
| ID | 1 |
| NAME | NAME2 |
| TYPE | MLRR |
| DFRUL | R2 |
| ADDR | 526766 |
| RRUL | P1 |
| SPRR | FALSE |
| ISGALW | FALSE |
| ISUTWD | FALSE |
| | |
| | |
| Total count | 10 |
| | |
| There is together 1 report | |
| | |
| END_BLOCK | |
| | |
| | |
| ..d 2019-03-07 17:35:52 | |
| KLAPW | #075288 |
| STAGE=1, ID=2, TYPE=MLRR | |
| | |
| | |
| STAGE | 1 |
| ID | 2 |
| NAME | NAME3 |
| TYPE | MLRR |
| DFRUL | P1 |
| ADDR | 232424 |
| RRUL | R2 |
| SPRR | FALSE |
| ISGALW | FALSE |
| ISUTWD | FALSE |
| | |
| ADDR | 13112 |
| RRUL | R2 |
| SPRR | FALSE |
| ISGALW | FALSE |
| ISUTWD | FALSE |
| | |
| ADDR | 131223 |
| RRUL | R2 |
| SPRR | FALSE |
| ISGALW | FALSE |
| ISUTWD | FALSE |
| | |
| ADDR | 111324 |
| RRUL | R2 |
| SPRR | FALSE |
| ISGALW | FALSE |
| ISUTWD | FALSE |
| | |
| ADDR | 56543 |
| RRUL | R2 |
| SPRR | FALSE |
| ISGALW | FALSE |
| ISUTWD | FALSE |
| | |
| ADDR | 11133 |
| RRUL | R2 |
| SPRR | FALSE |
| ISGALW | FALSE |
| ISUTWD | FALSE |
+----------------------------+---------+
答案 0 :(得分:2)
如果我们可以假设您的源数据始终按字段顺序排序,即使不是每个记录都填充了所有字段,那么我们可以提取所需的数据:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1),
#"Added Field Index" = Table.AddColumn(#"Added Index", "Field Index", each List.PositionOf({"STAGE","ID","NAME","TYPE","DFRUL","ADDR","RRUL","SPRR","ISGALW","ISUTWD"},[Decription]), Int64.Type),
#"Added Previous Field Index" = Table.AddColumn(#"Added Field Index", "Previous Field Index", each try #"Added Field Index"[Field Index]{[Index]-1} otherwise null, Int64.Type),
#"Added Record Index" = Table.AddColumn(#"Added Previous Field Index", "Record Index", each if [Field Index] < [Previous Field Index] or [Previous Field Index] = null then [Index] else null, Int64.Type),
#"Filled Down Record Index" = Table.FillDown(#"Added Record Index",{"Record Index"}),
#"Record Numbers" = Table.AddIndexColumn(Table.Group(#"Filled Down Record Index", {"Record Index"}, {}), "Record", 1, 1),
#"Merged Record Numbers" = Table.NestedJoin(#"Filled Down Record Index",{"Record Index"},#"Record Numbers",{"Record Index"},"Filled Down",JoinKind.LeftOuter),
#"Expanded Record Numbers" = Table.ExpandTableColumn(#"Merged Record Numbers", "Filled Down", {"Record"}, {"Record"}),
#"Selected Columns" = Table.SelectColumns(#"Expanded Record Numbers",{"Decription", "Value", "Record"}),
#"Pivoted Column" = Table.Pivot(#"Selected Columns", List.Distinct(#"Selected Columns"[Decription]), "Decription", "Value"),
#"Removed Other Columns" = Table.SelectColumns(#"Pivoted Column",{"STAGE", "ID", "NAME", "TYPE", "DFRUL", "ADDR", "RRUL"})
in
#"Removed Other Columns"