首页 文章

PowerBI DAX公式计算前2年的月平均值

提问于
浏览
0

我有一个180天退货政策的产品 . 我在Sales表中跟踪产品的销售情况和退货(与销售当天相关) . 例如 . 如果我在2017年10月26日销售产品并于2017年11月15日退货,则退货栏将于10/26/2017填充 .

我想根据过去两年同月的平均回报计算当月的估计回报 . 例如:

Sales       
Date        Sales    Returns
10/21/2018  500 
10/20/2018  120 
10/21/2017  546      254
10/20/2017  185      90
10/21/2016  255      120
10/20/2016  153      20

聚合值:

Sales   
Month   Sales To Return Ratio
Oct-18  
Oct-17  0.470588235
Oct-16  0.343137255

过去2年的平均10月回报率:0.424934153

Sales           
Month       Sales To Return Ratio   Expected Returns    
Oct-18                              550.9920983 (Return for prodcuts sold in last 2 Oct / by Sales in Oct of last 2 years) * Sales in Oct 2018
Oct-17      0.470588235     
Oct-16      0.343137255

我如何通过获取过去2年中该月的平均回报并乘以该月的销售额来创建一个可以给我任何月份的预期回报的度量 .

1 回答

  • 0

    如果您应用拼出的公式,使用总计返回和销售,则结果为263.45,而不是550.99 . 即

    (Return for products sold in last 2 Oct / by Sales in Oct of last 2 years) * Sales in Oct 2018

    =(484/1139)*620

    该结果也可以用DAX计算 . 如果您有Date表,则可以使用SamePeriodLastYear和DateAdd来计算过去两年的总计 . 以下公式使用度量来计算Sales和Return列的总和 .

    =(
        (
           CALCULATE([Total Returns],SAMEPERIODLASTYEAR(DateTable[Date]))
           +CALCULATE([Total Returns],DATEADD(DateTable[Date],-2,YEAR))
         )
         /
         (
             CALCULATE([Total Sales],SAMEPERIODLASTYEAR(DateTable[Date]))
             +CALCULATE([Total Sales],DATEADD(DateTable[Date],-2,YEAR))
          )
       )
       *[Sum of Sales]
    

    enter image description here

相关问题