简体   繁体   English

Power BI / DAX:按计算列对计算表进行排序

[英]Power BI / DAX: Sort Calculated Table by Calculated Column

I have a Power BI data model with a DAX calculated table used as a dimension that is calculated with VALUES from a fact table with multiple occurrences of each value, so it is a 1:M relationship.我有一个 Power BI 数据模型,其中一个 DAX 计算表用作维度,该维度使用来自每个值多次出现的事实表中的 VALUES 计算,因此它是 1:M 关系。

In my report I want to use the calculated table values as a slicer with the options presented in a specific order other than alphabetical.在我的报告中,我想将计算出的表格值用作切片器,其中的选项按字母顺序以外的特定顺序显示。 Therefore in the calculated table, I created a calculated column that assigns a number to each row based on a SWITCH function.因此,在计算表中,我创建了一个计算列,该列根据 SWITCH 函数为每一行分配一个数字。 However, when I then try to "Sort by Column" in Power BI, it throws an error indicating that it is a circular reference.但是,当我尝试在 Power BI 中“按列排序”时,它会抛出一个错误,表明它是一个循环引用。 How else can I define the sort order?我还能如何定义排序顺序?

Here is an example data/calculated tables:这是一个示例数据/计算表:

'Source' fact table: “来源”事实表:

Dimension_Values Dimension_Values
a_order_third a_order_third
a_order_third a_order_third
b_order_first b_order_first
b_order_first b_order_first
c_order_second c_order_second
c_order_second c_order_second

Calculated_Dim_Table = VALUES('Source'[Dimension_Values]) Calculated_Dim_Table = VALUES('Source'[Dimension_Values])

Dimension_Values Dimension_Values
a_order_third a_order_third
b_order_first b_order_first
c_order_second c_order_second

Calculated_Order_Column = SWITCH('Calculated_Dim_Table'[Dimension_Values],"b_order_first",1,"c_order_second",2,"a_order_third",3) Calculated_Order_Column = SWITCH('Calculated_Dim_Table'[Dimension_Values],"b_order_first",1,"c_order_second",2,"a_order_third",3)

*Sort 'Calculated_Dim_Table'[Dimension_Values] by 'Calculated_Dim_Table[Calculated_Order_Column] so that desired output is *按 'Calculated_Dim_Table[Calculated_Order_Column] 对 'Calculated_Dim_Table'[Dimension_Values] 进行排序,以便所需的输出为

Dimension_Values Dimension_Values Calculated_Order_Column Calculated_Order_Column
b_order_first b_order_first 1 1
c_order_second c_order_second 2 2
a_order_third a_order_third 3 3

Issue: Power BI is saying this is creating a circular dependency - is there another way to define the sort order of a column without referencing it to avoid the circular dependency?问题:Power BI 说这是创建循环依赖 - 是否有另一种方法来定义列的排序顺序而不引用它以避免循环依赖?

I think it throws an circular reference error, caused DAX internally decides the the order of execution.我认为它会引发循环引用错误,导致 DAX 内部决定执行顺序。 In this case, DAX wants to sort the dimension values upon loading, but it can't cause it depends on a calculated column thst in turn depends on dimension values.在这种情况下,DAX 希望在加载时对维度值进行排序,但它不能导致它依赖于计算列 thst 又依赖于维度值。 So it is a circular reference indeed.所以它确实是一个循环引用。 I would advise you to this in PQ and then load both the tables and then you can do the sorting in t2 with no trouble.我建议你在 PQ 中这样做,然后加载两个表,然后你可以在 t2 中毫无问题地进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM