gpt4 book ai didi

excel - PowerQuery - 年度动态变化

转载 作者:行者123 更新时间:2023-12-04 22:12:37 24 4
gpt4 key购买 nike

我正在反透视和转置(输入),以便为内部系统格式化(输出)。 @RonRosenfeld 在 solution 中提供的解决方案解决了这个问题。
但是,输出的年份被硬编码为 2022,这很好,直到我们到达今年的第二个半年,然后我想动态地将新月份更改为 2023,即 01.2023、02.2023...
我想不出动态解决方案,所以我尝试了“财政年度”,即使在修改数据类型后也不起作用。
[输入]
[2]
[输出]
[3]


Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],

#"Changed Type" = Table.TransformColumnTypes(Source,{
{"Index", Int64.Type}, {"Person", Int64.Type}, {"Dept", Int64.Type},
{"Jan", Int64.Type}, {"Feb", Int64.Type}, {"Mar", Int64.Type},
{"Apr", Int64.Type}, {"May", Int64.Type}, {"Jun", Int64.Type},
{"Jul", Int64.Type}, {"Aug", Int64.Type}, {"Sep", Int64.Type},
{"Oct", Int64.Type}, {"Nov", Int64.Type}, {"Dec", Int64.Type},
{"Time", type datetime}, {"User", type text}},"en-150"),

#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type",
{"Index", "Person", "Dept", "Time", "User"}, "Month", "Sales"),

mnthCol = Table.TransformColumns(#"Unpivoted Other Columns", {"MNTH", each
Date.ToText(Date.FromText("1-" & _ & DateTime.ToText(Date.AddMonths(DateTime.LocalNow(),8),"yyyy")),"MM.yyyy"),type text}),
#"Changed Type1" = Table.TransformColumnTypes(mnthCol,{{"MNTH", type date}}),

FC = Table.AddColumn(#"Changed Type1", "Fiscal Month", each if Date.ToText(Date.Month([MNTH])) >=7 then Date.ToText(Date.Month([MNTH]))-6 else Date.ToText(Date.Month([MNTH]))+6),

#"Reordered Columns" = Table.ReorderColumns(mnthCol,{"Index", "Person", "Dept", "Month", "Sales", "Time", "User"}),

rename = Table.RenameColumns(#"Reordered Columns",{
{"Time","STMP"},
{"Dept","Depr"}
})
in
rename

最佳答案

调整为original solution是改变

mnthCol = Table.TransformColumns(#"Unpivoted Other Columns", {"Month", each 
Date.ToText(Date.FromText("1-" & _ & "-2022"),"M.yyyy"),type text}),
类似于
   mnthCol = Table.TransformColumns(#"Unpivoted Other Columns", {"Month", each 
if Date.Month(Date.FromText("1-" & _ & "-1900"))<7 then
Date.ToText(Date.FromText("1-" & _ & "-2023"),"M.yyyy")
else
Date.ToText(Date.FromText("1-" & _ & "-2022"),"M.yyyy")
,type text}),
但是您必须以某种方式动态设置 7 以确定哪些月份在哪一年

关于excel - PowerQuery - 年度动态变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71796455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com