Power Bi:计算其他表

时间:2017-07-17 05:44:00

标签: powerbi

我有公司的休假数据。  以下是示例数据:

STAFF  PL   CL  ML  SP  LWP TL  Month
A      1    2   0   0   6   9   April
B      14   0   4   0   0   18  April
A      1    2   0   0   1   4   May
B      1    0   4   0   0   5   May
A      1    2   0   0   2   5   June
B      2    0   4   0   0   6   June

我想将这些数据转换为这样的表结构 -

以下是示例数据:

Types of Leave  Count   Month
ML                89    4
CL                114   4
LWP               17    4
PL                135   4
SP                89    4
ML                89    5
CL                114   5
LWP               17    5
PL                135   5
SP                89    5
ML                89    6
CL                114   6
LWP               17    6
PL                135   6
SP                89    6

可以使用SelectColumns,Summarizecolumn dax函数吗?

我试过了 -

SUMMARIZE(Table1, Table1[CL],Table1[LWP],Table1[ML],Table1[PL],"CL2", SUM(Table1[CL]), "ML2", SUM(Table1[ML]), "LW2P",SUM(Table1[LWP]), "P2L", SUM(Table1[PL]))

它给了我奇怪的结果。

1 个答案:

答案 0 :(得分:0)

删除名称和人员列后取消移动数据。然后将月份名称转换为月份编号并构建数据透视表。

屏幕截图显示了Excel中的结果,但在Power BI中也可以这样做。

enter image description here

这是我点击功能区图标时记录的查询的M代码:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"STAFF", type text}, {"PL", Int64.Type}, {"CL", Int64.Type}, {"ML", Int64.Type}, {"SP", Int64.Type}, {"LWP", Int64.Type}, {"TL", Int64.Type}, {"Month", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"STAFF", "TL"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Month"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Other Columns",{{"Attribute", "Type of Leave"}, {"Value", "Count"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Custom", each Date.FromText([Month]&"1 2017")),
    #"Extracted Month" = Table.TransformColumns(#"Added Custom",{{"Custom", Date.Month}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Extracted Month",{"Month"}),
    #"Renamed Columns1" = Table.RenameColumns(#"Removed Columns1",{{"Custom", "Month"}})
in
    #"Renamed Columns1"