一列的MAX值总和

时间:2019-07-09 20:52:59

标签: powerbi dax

情况

我有一个列(退款),该列采用每天的最大值,这样我就不会重复退款。

refund =
var calcul = 
        CALCULATE(
            SUM(Query1[amount]),
            USERELATIONSHIP(Query1[created_at], DateTable[Date]),
            Query1[kind] = "refund",
            Query1[status] = "success"       
            )

这每天都有效,但总数就是该列的最大值

目标

我需要这种方法来计算净销售额。我已经有总销售额指标,但是汇总后我的退款公式不起作用。

我尝试过的工作(感谢Alexis Olson):

refund =
var calcul = 
        CALCULATE(
            SUM(Query1[amount]),
            USERELATIONSHIP(Query1[created_at], DateTable[Date]),
            Query1[kind] = "refund",
            Query1[status] = "success"       
            )
    return 
        SUMX(DISTINCT(Query1[orderId]), calcul)

但是输出是意外的。它基本上采用每个值,并将其乘以当天(是否退款)的订单ID的不重复计数。

因此,我尝试将其除以订单ID的不同计数,但是总行数取最大值的相同问题出现了。

这是我使用下面提供的解决方案得到的输出:

Returns column is correct but total isn't. Refund column is not showing all the values (date relationship issue) but the total works

关系:

Query1 [created_at] DateTable [Date](无效)

Query1 [orderDate] DateTable [Date](有效)

我的退货标准:

Returns = 
CALCULATE(
    MAX(Query1[amount]),
    USERELATIONSHIP(Query1[created_at], DateTable[Date]),
    Query1[kind] = "refund",
    Query1[status] = "success"       
    )

2 个答案:

答案 0 :(得分:0)

您非常接近可行的方法。尝试将calcul更改为摘要表,而不是像这样的单个值标量:

refund =
VAR Summary =
    SUMMARIZE (
        Query1,
        Query1[orderId],
        "MaxValue", CALCULATE (
            MAX ( Query1[amount] ),
            USERELATIONSHIP ( Query1[created_at], DateTable[Date] ),
            Query1[kind] = "refund",
            Query1[status] = "success"
        )
    )
RETURN
    SUMX ( Summary, [MaxValue] )

答案 1 :(得分:0)

解决我的问题的一种方法是在摘要之前使用CALCULATETABLE,然后 使用Alexis上面建议的SUMX

Returns = 
VAR sumary = 
    CALCULATETABLE(
        SUMMARIZE(
            Query1,
            Query1[orderId],
            "maxValue",CALCULATE(
                MAX(Query1[amount]),
                Query1[kind]= "refund",
                Query1[status] = "success"
            )
        ),USERELATIONSHIP(Query1[trx_date],DateTable[Date]))
    RETURN
        SUMX(sumary,[maxValue])