[英]Power Bi - two column dates
I would like an help for power bi.我想要一个关于 power bi 的帮助。 I have several projects in rows and 12 months in different columns for budget, plus other 12 months for actual expenses.
我有几个项目在行中,在不同的列中有 12 个月的预算,另外还有 12 个月的实际费用。
I have done unpivot to have the actual expenses and budget in two different columns (instead of 24 --> 2 times 12 months).我已经在两个不同的列(而不是 24 --> 12 个月的 2 倍)中进行了逆向分析。 The problem is that I end up with two different columns with the date, one for the actual sales and one for budget and I am stucked.
问题是我最终得到了两个不同的日期列,一个是实际销售额,另一个是预算,我被卡住了。 How to solve this issue?
如何解决这个问题? Any better way to do?
有什么更好的办法吗?
Thanks谢谢
With adequate data, it is now easier to see what you are dealing with and what you want.有了足够的数据,现在可以更轻松地了解您正在处理什么以及您想要什么。
Explore the Applied steps and also read the comments in the M-Code to better understand the algorithm探索应用步骤并阅读 M 代码中的注释以更好地理解算法
let
Source = Excel.CurrentWorkbook(){[Name="Table5"]}[Content],
//Get list of monthcolumns for setting data type and Count
monthCols = List.Select(Table.ColumnNames(Source), each
Text.Contains(_,"Jan",Comparer.OrdinalIgnoreCase)
or Text.Contains(_,"Feb",Comparer.OrdinalIgnoreCase)
or Text.Contains(_,"Mar",Comparer.OrdinalIgnoreCase)
or Text.Contains(_,"Apr",Comparer.OrdinalIgnoreCase)
or Text.Contains(_,"May",Comparer.OrdinalIgnoreCase)
or Text.Contains(_,"Jun",Comparer.OrdinalIgnoreCase)
or Text.Contains(_,"Jul",Comparer.OrdinalIgnoreCase)
or Text.Contains(_,"Aug",Comparer.OrdinalIgnoreCase)
or Text.Contains(_,"Sep",Comparer.OrdinalIgnoreCase)
or Text.Contains(_,"Oct",Comparer.OrdinalIgnoreCase)
or Text.Contains(_,"Nov",Comparer.OrdinalIgnoreCase)
or Text.Contains(_,"Dec",Comparer.OrdinalIgnoreCase)),
typer = {{"Project", Int64.Type},{"Manager", Text.Type}} &
List.Transform(monthCols, each {_, Int64.Type}),
numMonths = List.Count(monthCols)/3,
#"Changed Type" = Table.TransformColumnTypes(Source,typer),
//Unpivot all except Project and Manager columns
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Project", "Manager"}, "Attribute", "Value"),
//Split the Attribute (budget date/type) column to separate the Month and the Type
#"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute",
Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Month", "ValueType"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Month", type text}, {"ValueType", type text}}),
//Add Index and Modulo (number of months) for later sorting
#"Added Index" = Table.AddIndexColumn(#"Changed Type1", "Index", 0, 1, Int64.Type),
#"Calculated Modulo" = Table.TransformColumns(#"Added Index", {{"Index", each Number.Mod(_, numMonths), type number}}),
//Pivot on ValueType
#"Pivoted Column" = Table.Pivot(#"Calculated Modulo", List.Distinct(#"Calculated Modulo"[ValueType]), "ValueType", "Value"),
//Add another Index - Integer/Division for sorting
#"Added Index1" = Table.AddIndexColumn(#"Pivoted Column", "Index.1", 0, 1, Int64.Type),
#"Inserted Integer-Division" = Table.AddColumn(#"Added Index1", "Integer-Division",
each Number.IntegerDivide([Index.1], numMonths), Int64.Type),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Integer-Division",{"Index.1"}),
//Sort, reorder and rename
#"Sorted Rows" = Table.Sort(#"Removed Columns",{{"Integer-Division", Order.Ascending}, {"Index", Order.Ascending}}),
#"Removed Columns1" = Table.RemoveColumns(#"Sorted Rows",{"Index", "Integer-Division"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns1",{"Project", "Month", "Budget", "Actual", "Latest", "Manager"})
in
#"Reordered Columns"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.