尝试根据过滤器和ALLEXCEPT计算每日百分比

时间:2019-04-24 22:14:29

标签: powerbi dax

我有一个我之前问过的以下问题,但是我想进一步过滤除月份和年份之外的其他列,我想添加“资源名称,记录类型”

How to calculate daily percentage over month on month volume?

下面我尝试添加无法正常工作的allexcept

Total_Percentage = 
VAR TotalPerMonth =
    CALCULATE (
        SUM ( data1[Actual] ),
        FILTER ( data1, data1[Month].[Month] = EARLIER ( data1[Month].[Month] ) ),
        FILTER ( data1, data1[Month].[Year] = EARLIER ( data1[Month].[Year] ) ),
        ALLEXCEPT(data1,data[RecordType],data1[Resource Name]),
                FILTER ( data1, data1[Flag] = 1 )
    )
RETURN
    DIVIDE ( data1[actual], TotalPerMonth, 0 )

2 个答案:

答案 0 :(得分:2)

这可能会更加优化:

Total_Percentage =
VAR TotalPerMonth =
    CALCULATE (
        SUM ( data1[Actual] ),
        FILTER (
            ALLEXCEPT ( data1, data[RecordType], data1[Resource Name] ),
            data1[Month].[Month] = EARLIER ( data1[Month].[Month] ) &&
            data1[Month].[Year] = EARLIER ( data1[Month].[Year] ) &&
            data1[Flag] = 1
        )
    )
RETURN
    DIVIDE ( data1[actual], TotalPerMonth, 0 )

答案 1 :(得分:0)

我认为这应该对我有用。如果您有任何优化,请告诉我

Total_Percentage = 
VAR TotalPerMonth =
    CALCULATE (
        SUM ( data1[Actual] ),
        FILTER ( data1, data1[Month].[Month] = EARLIER ( data1[Month].[Month] ) ),
        FILTER ( data1, data1[Month].[Year] = EARLIER ( data1[Month].[Year] ) ),
        FILTER(ALL('data1'),[Resource Name]=EARLIER('data1'[Resource Name])),
        FILTER(ALL('data1'),[RecordType]=EARLIER('data1'[RecordType])),
        FILTER ( data1, data1[Flag] = 1 )
    )
RETURN
    DIVIDE ( data1[actual], TotalPerMonth, 0 )