(很抱歉,如果 Power Query 的公开版本中尚未包含以下任何功能 - 这适用于今天的 Power BI 设计器!)
从文件夹给我:
添加一个自定义步骤,使用Text.FromBinary
名为Text
获取文件文本的列:
然后删除除Folder Path
and之外的每一列Text
:
从那里,按分隔符拆分文件夹路径列\
然后只保留带有日期的路径列:
接下来,将两个文本列与 custom 合并:
,你就完成了!
运行它来设置上面使用的数据:
cd c:\
mkdir alldata
cd alldata
mkdir 201501
mkdir 201502
mkdir 201503
echo Made $100 > 201501\Revenues.txt
echo Made $200 > 201502\Revenues.txt
echo Made $300 > 201503\Revenues.txt
此转换的完整 M 源代码:
let
Source = Folder.Files("c:\AllData"),
#"Added Custom" = Table.AddColumn(Source, "Text", each Text.FromBinary([Content])),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Folder Path", "Text"}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Removed Other Columns","Folder Path",Splitter.SplitTextByDelimiter("\"),{"Folder Path.1", "Folder Path.2", "Folder Path.3", "Folder Path.4"}),
#"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Folder Path.1", type text}, {"Folder Path.2", type text}}),
#"Removed Other Columns1" = Table.SelectColumns(#"Changed Type",{"Folder Path.3", "Text"}),
#"Merged Columns" = Table.CombineColumns(#"Removed Other Columns1",{"Folder Path.3", "Text"},Combiner.CombineTextByDelimiter(": ", QuoteStyle.None),"Revenues")
in
#"Merged Columns"