如何在Power BI中使用SUMX和表表达式获取列总计

时间:2020-01-13 21:16:57

标签: powerbi dax powerbi-desktop

我在db.collection.aggregate([{ $match: { field1: 'A' } }, { $project: { field1: 1, array1: { $size: { $filter: { "input": "$array1", "as": 'each', "cond": { "$eq": ["$$each.field_1", "true"] } } } } } }]) 函数中有一个表表达式。 如何在我的方案中获得总计“打开”列?

SUMX()

Enter image description here

更新:感谢@ CR7SMS。

但是现在看起来有点高了:

我尝试过:

TestMeasure =
    SUMX (
        ADDCOLUMNS (
            SUMMARIZE (
                FILTER (
                    SumByClaim,
                    SumByClaim[TransactionDate] >= FIRSTDATE ( SumByClaim[TransactionDate] )
                        && SumByClaim[TransactionDate] <= LASTDATE ( SumByClaim[TransactionDate] )
                ),
                SumByClaim[ClaimNumber],
                SumByClaim[ClaimantID],
                SumByClaim[ClaimStatus],
                "MaxTransDate", MAX ( SumByClaim[TransactionDate] )
            ),
            "Open", IF (
                SumByClaim[ClaimStatus] = "Open"
                    && [MaxTransDate] = MAX ( SumByClaim[TransactionDate] ),
                1,
                0
            )
        ),
        [Open]
    )

Enter image description here

1 个答案:

答案 0 :(得分:0)

我在计算中添加了SUMX,这给了我更高的总数。我不确定结果是否是您想要的,但是您可以尝试一下:

TestMeasure = 
SUMX(SumByClaim,SUMX (
    ADDCOLUMNS (
        SUMMARIZE (
            FILTER (
                SumByClaim,
                SumByClaim[TransactionDate] >= FIRSTDATE ( SumByClaim[TransactionDate] )
                    && SumByClaim[TransactionDate] <= LASTDATE ( SumByClaim[TransactionDate] )
            ),
            SumByClaim[ClaimNumber],
            SumByClaim[ClaimantID],
            SumByClaim[ClaimStatus],
            "MaxTransDate", MAX ( SumByClaim[TransactionDate] )
        ),
        "Open", IF (
            SumByClaim[ClaimStatus] = "Open"
                && [MaxTransDate] = MAX ( SumByClaim[TransactionDate] ),
            1,
            0
        )
    ),
    [Open]
))