运行一个度量DAX的总计

时间:2017-12-28 13:59:29

标签: excel powerpivot dax

我正在尝试计算我创建的度量的运行总计,我可以使用"显示值为"来获取数据透视表以显示它。但是我无法使用新的测量方法实现相同的目标,我需要一个新的测量方法,以便我可以计算年初至今的平均值

使用以下公式,我得到各行的总和,而不是每月聚合行的总和

任何帮助将不胜感激 感谢

       Measure2:=CALCULATE(SUMX(Table,[measure1]),FILTER (
                ALL(  Calendar[Date]),
                Calendar[Date] <= MAX (Calendar[Date] )
            )
        )

Measure1:=if(sum(AMOUNT)=0,Blank(),if(sum(AMOUNT)<0,[WAT],if([Countback]=1,(SUM(AMOUNT)/[CumulativSales1])*[Sum of Days],
                              if([Countback]=2,[Sum of Days]+((SUM(AMOUNT))-[CumulativSales1])/([CumulativSales2]-[CumulativSales1])*[Days Previous],
                              if([Countback]=3,[Sum of Days]+[Days Previous]+((SUM(AMOUNT))-[CumulativSales2])/([CumulativSales3]-[CumulativSales2])*[Days Previous2],
                               if([Countback]=4,[Sum of Days]+[Days Previous]+[Days Previous2]+((SUM(AMOUNT))-[CumulativSales3])/([CumulativSales4]-[CumulativSales3])*[Days Previous3],
                           if([Countback]=5,[Sum of Days]+[Days Previous]+[Days Previous2]+[Days Previous3]+((SUM(AMOUNT))-[CumulativSales4])/([CumulativSales5]-[CumulativSales4])*[Days Previous4],200)))))))  


    AverageSaleWeight2:=if(HASONEVALUE(Calendar[Date]),
    CALCULATE(sum(INVOICE[Days Given * Amount])/sum(INVOICE[Amount GBP]),
    DATEADD(Calendar[Date],-2,MONTH)),BLANK())

    AverageSaleWeight3:=if(HASONEVALUE(Calendar[Date]),
    CALCULATE(sum(INVOICE[Days Given * Amount])/sum(INVOICE[Amount GBP]),
    DATEADD(Calendar[Date],-3,MONTH)),BLANK())

    .....


    Countback:=IF((DIVIDE([CumulativSales1],sum(Aging[OPEN_DOM_AMOUNT]))>=0.9999,1,
                               IF((DIVIDE([CumulativSales2],SUM(Aging[OPEN_DOM_AMOUNT]))>=0.9999,2,
                              IF((DIVIDE([CumulativSales3],SUM(Aging[OPEN_DOM_AMOUNT]))>=0.9999,3,
                              IF((DIVIDE([CumulativSales4],sum(Aging[OPEN_DOM_AMOUNT]))>=0.9999,4,
                              IF((DIVIDE([CumulativSales5],sum(Aging[OPEN_DOM_AMOUNT]))>=0.9999,5,6))))))))))


    CumulativSales1:=CALCULATE(SUM(INVOICE[Amount GBP]),
    DATESINPERIOD(Calendar[Date],
    LASTDATE(Calendar[Date]),-1,MONTH))




    CumulativSales2:=CALCULATE(SUM(INVOICE[Amount GBP]),
    DATESINPERIOD(Calendar[Date],
    LASTDATE(Calendar[Date]),-2,MONTH))





    WAT:=if(sum([AMOUNT])=0,Blank(),IF([Countback]=1,[AverageSaleWeight],IF([Countback]=2,[AverageSaleWeight1],IF([Countback]=3,[AverageSaleWeight2],IF([Countback]=4,[AverageSaleWeight3],IF([Countback]=5,
    [AverageSaleWeight4],IF([Countback]=6,[AverageSaleWeight5],30)))))))


    Days Previous:=CALCULATE(SUM(Calendar[Days]),
    DATESINPERIOD(Calendar[Date],
    LASTDATE(Calendar[Date]),-2,MONTH))-CALCULATE(SUM(Calendar[Days]),
    DATESINPERIOD(Calendar[Date],
    LASTDATE(Calendar[Date]),-1,MONTH))


    Days Previous2:=CALCULATE(SUM(Calendar[Days]),
    DATESINPERIOD(Calendar[Date],
    LASTDATE(Calendar[Date]),-3,MONTH))-CALCULATE(SUM(Calendar[Days]),
    DATESINPERIOD(Calendar[Date],
    LASTDATE(Calendar[Date]),-2,MONTH))

    ....

`

enter image description here

1 个答案:

答案 0 :(得分:1)

试试这个修订版本,看看你是否得到了预期的结果:

Measure3 := CALCULATE( 
    SUMX( VALUES(Calendar[Month]), [measure1] )
    , FILTER( 
         ALL(Calendar)
        , Calendar[Date] <= MAX(Calendar[Date])
        && Calendar[Year] = MAX(Calendar[Year])
        )
    )

最新编辑:添加了SUMX VALUES