如何在 DAX Studio 中逆透视数据表?

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

我有一个如下所示的

datatable
,我想在 DAX studio 中取消旋转它。新的
MonthFY
列应包含日期值。非常感谢。

    EVALUATE
Var mydf =
DATATABLE (
    "Group A", STRING, "Variable", STRING,
    "Apr FY23", CURRENCY, "May FY24", CURRENCY,
    "Jun FY24", CURRENCY,"Jul FY24", CURRENCY,

    {
    
        { "Gorup A", "Additions_at_Cost", 10000, 20000 ,50000,60000},
        { "Group A", "Accum_Dep", 5000, 6000, 75000,8500},
        { "Group A", "Accum_Dep Dispositions Impairments",10 ,10,1000, 1000},
        { "Group A", "Dispositions", 999,999, 5000,5000},
        
        { "Gorup B", "Additions_at_Cost", 10000, 20000 ,50000,60000},
        { "Group B", "Accum_Dep", 5000, 6000, 75000,8500},
        { "Group B", "Accum_Dep Dispositions Impairments", 10,10,1000, 1000},
        { "Group B", "Dispositions", 999,999, 5000,5000}
    }
)
Return mydf

我所做的是;

EVALUATE
VAR t1 = SELECTCOLUMNS ( 'mydf',   "Group A", {"Group A", "Group B"}, 
"Variable", {"Additions_at_Cost","Accum_Dep","Accum_Dep Dispositions Impairments","Dispositions"},   
"MonthFY", "Apr FY23","Value", [Apr FY23] )

VAR t2 = SELECTCOLUMNS ( 'mydf',   "Group A", {"Group A", "Group B"}, 
"Variable", {"Additions_at_Cost","Accum_Dep","Accum_Dep Dispositions Impairments","Dispositions"},    
"MonthFY", "May FY24","Value", [May FY24] )

VAR t3 = SELECTCOLUMNS ( 'mydf',   "Group A", {"Group A", "Group B"}, 
"Variable", {"Additions_at_Cost","Accum_Dep","Accum_Dep Dispositions Impairments","Dispositions"},   
"MonthFY", "Jun FY24","Value", [Jun FY24] )

VAR t4 = SELECTCOLUMNS ( 'mydf',   "Group A", {"Group A", "Group B"}, 
"Variable", {"Additions_at_Cost","Accum_Dep","Accum_Dep Dispositions Impairments","Dispositions"},   
"MonthFY", "July FY24","Value",[July FY24] )

RETURN UNION ( t1, t2, t3, t4 )
powerbi dax data-manipulation powerbi-desktop daxstudio
2个回答
2
投票
Table 2 = 
UNION(
    SELECTCOLUMNS('Table', "Group A", 'Table'[Group A],"Variable", 'Table'[Variable], "Attribute", "AprFY23", "Value", 'Table'[Apr FY23]),
    SELECTCOLUMNS('Table', "Group A", 'Table'[Group A],"Variable", 'Table'[Variable], "Attribute", "MayFY24", "Value", 'Table'[May FY24]),
    SELECTCOLUMNS('Table', "Group A", 'Table'[Group A],"Variable", 'Table'[Variable], "Attribute", "JunFY24", "Value", 'Table'[Jun FY24]),
    SELECTCOLUMNS('Table', "Group A", 'Table'[Group A],"Variable", 'Table'[Variable], "Attribute", "JulFY24", "Value", 'Table'[Jul FY24])
)


0
投票

正如 Davide 所说,我会在 PowerQuery 中执行此操作,除非您出于某种原因需要原始格式的数据。

您只需进入 PowerQuery 编辑器,选择前两列,然后选择 Unpivot Other Columns,您就应该完成设置了。

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