如何在DAX Studio中取消数据表?

How to Unpivot datatable in DAX Studio?

提问人:Seyma Kalay 提问时间:9/24/2023 最后编辑:Davide BacciSeyma Kalay 更新时间:9/25/2023 访问量:45

问:

我有一个如下所示,我想在 DAX 工作室中取消它。新列应包含日期值。提前非常感谢。datatableMonthFY

    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 数据操作 PowerBI 桌面 DAXStudio

评论

1赞 Davide Bacci 9/24/2023
实际上不建议在 DAX 中取消透视。你会接受Power Query解决方案吗?
0赞 Davide Bacci 9/24/2023
生成的表格究竟应该是什么样子的?
0赞 Seyma Kalay 9/24/2023
是的,它应该是一个有 3 列的表;组 A、变量和 MonthFY
0赞 Seyma Kalay 9/24/2023
宽数据集 -->长数据集

答:

2赞 Davide Bacci 9/25/2023 #1
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])
)

enter image description here

0赞 Pieter 9/25/2023 #2

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

只需进入 PowerQuery 编辑器,选择前两列,然后选择“取消透视其他列”,即可完成设置。