对行进行排序并在其位置保留空白

问题描述 投票:0回答:1

我有下表,有两列:

日期 书名
2022 年 1 月 1 日
标题1
标题2
2022 年 1 月 3 日 <- unsorted
2022年1月2日
标题3
2022年1月2日
标题4

Date
行充当
Book Title
列的子标题,但正如您所看到的,某些日期并非按升序排列。重复不是问题。

我的目标是实现以下目标(注意

Date
中未更改的空白单元格):

日期 书名(保持不变)
2022 年 1 月 1 日
标题1
标题2
2022 年 1 月 2 日 <- fixed sorting
2022年1月2日
标题3
2022 年 1 月 3 日 <- fixed sorting
标题4

但是,当我正常按升序排序时,会发生的情况是所有空白单元格都收集在表格顶部。我想将空白单元格保留在原来的位置。

我设法直接在 Excel 上执行此操作,方法是隐藏

Dates
中的空白,使用日期对剩余单元格进行排序,然后取消隐藏空白单元格。这让我可以保持空白单元格不变,并仅在已填充的单元格内对日期进行排序。

如何在 Power Query 上实现此目的?

excel powerquery data-cleaning m
1个回答
0
投票

尝试

let  Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
#"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Date", "Date - Copy"),
#"Filled Down" = Table.FillDown(#"Duplicated Column",{"Date - Copy"}),
#"Added Index" = Table.AddIndexColumn(#"Filled Down", "Index", 0, 1, Int64.Type),
#"Sorted Rows" = Table.Sort(#"Added Index",{{"Date - Copy", Order.Ascending}, {"Index", Order.Ascending}}),
#"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Date - Copy", "Index"})
in   #"Removed Columns"

© www.soinside.com 2019 - 2024. All rights reserved.