如何简化以下DAX语句?

时间:2017-05-04 17:50:14

标签: dax

我的DAX语句在复杂性方面继续增长,我觉得好像我正在高效地编写它。谁能帮我理解如何简化这个陈述?

EVALUATE
ADDCOLUMNS (
    ADDCOLUMNS (
        ADDCOLUMNS (
            ADDCOLUMNS (
                ADDCOLUMNS (
                    ADDCOLUMNS (
                        ADDCOLUMNS (
                            Query_NewSales,
                            "isKit", NOT (
                                ISBLANK (
                                    LOOKUPVALUE ( Query_Kits[KitName], Query_Kits[KitName], Query_NewSales[Item] )
                                )
                            )
                        ),
                        "AvgCPI", IF (
                            [isKit],
                            LOOKUPVALUE (
                                DAX_KitsPricedMissingRemoved[Total Price],
                                DAX_KitsPricedMissingRemoved[KitName], Query_NewSales[Item]
                            ),
                            LOOKUPVALUE (
                                DAXTable_NewPurchasesGroupedByItem[AvgCPI],
                                DAXTable_NewPurchasesGroupedByItem[Item], Query_NewSales[Item]
                            )
                        )
                    ),
                    "isValid", NOT ( ISBLANK ( [AvgCPI] ) )
                ),
                "VenueFeeCalculated", IF ( [isValid], [Sold Price] * [Linked.VenueFee] ),
                "TransactionFeeCalculated", IF ( [isValid], [Sold Price] * [Linked.PaymentFee] )
            ),
            "Gross Profit", IF (
                [isValid],
                [Sold Price] - [VenueFeeCalculated]
                    - [TransactionFeeCalculated]
                    - [Shipping Cost]
            )
        ),
        "Total Fees", [TransactionFeeCalculated] + [VenueFeeCalculated],
        "Net Profit", IF ( [isValid], [Gross Profit] - [AvgCPI] )
    ),
    "Fees Percent", IF ( [isValid], [Linked.VenueFee] + [Linked.PaymentFee] ),
    "Shipping Percent", IF ( [isValid], [Shipping Cost] / [Sold Price] ),
    "Overhead Percent", IF ( [isValid], ( [Sold Price] - [Gross Profit] ) / [Sold Price] )
)

这段代码似乎效率低下,因为它创建了一大堆虚拟表,但是如果不这样做,我就无法引用我稍后在查询中添加的列。我不想在继续查询时有重复,三次重复等。似乎必须有一种方法可以在没有所有嵌套的情况下做到这一点。

1 个答案:

答案 0 :(得分:0)

您可以将查询分解为多个度量:

let objectFront = { id: 'a', name: 'b', value: 'c', color: "d" };
let objectBack = (({id, name, value}) => ({id, name, value}))(objectFront);