同比、环比、累计值在Power BI中的计算

我的个人博客:https://lixiaohui.live

0. 一些名词的解释

0.1 解释

名词 中文名词 意思
YOY 同比增长率 Year Over Year: 按年度计的增长率
MOM 环比增长率 Month Over Month: 按月度计的增长率
YTD 年累计 Year to Date: 指年初至当前日期(不含今日)累计
QTD 季累计 Quarter to Date: 季度初至今累计
MTD 月累计 Month to Date: 月初至今累计

YTD stands for year to date – from the beginning of the current year, up to but not including today. Once again, make sure you know where your company goes by the calendar year or the fiscal year, as the latter may not begin on January 1st.

QTD stands for “Quarter to Date”. It’s used in exactly the same way as MTD, except you’re looking at the time period from the start of this quarter until now. Be careful though: this can refer to either the calendar or the fiscal quarter.

MTD stands for “Month to Date”. It’s the period starting from the beginning of the current month up until now… but not including today’s date, because it might not be complete yet.

0.2 示例

(YOY)同比:13年3月和14年3月两个时段的数据进行对比。
(MOM)环比:14年4月和14年3月两个相邻时间段的数据进行对比。
假如今天是2017年12月3号...
(YTD)年累计:YTD将计算从2017年1月1号到2017年12月3号量值的总计。
(QTD)季累计:QTD将计算从2017年9月1号到2017年12月3号量值的总计。
(MTD)月累计:MTD将计算从2017年12月1号到2017年12月3号量值的总计。

DAX 语法参考链接:MSDN。
学习资料来自于Youtube:这里。

1. 同比

1.1 创建[当期]量值的聚合(sum)

Total Amount TY= SUM(Sales[Amount])

1.2 创建[上一期]量值的聚合(sum)

Total Amount LY= CALCULATE(Total Amount TY, SAMEPERIODLASTYEAR(Date[Datekey]))

1.3 创建[当期]和[上一期]的[差值]

Diff. = Total Amount TY - Total Amount LY

1.4 计算[差值]占[当期]量值的比例(YOY %)

YOY % = IF(
    ISBLANK(Total Amount TY),
    0,
    Diff. / Total Amount TY)

显示结果:


同期值.png

2.环比

2.1 创建[当期]量值的聚合(sum)

Total Amount TM= SUM(Sales[Amount])

2.2 创建[前一期]量值的聚合(sum)

Total Amount PM = CALCULATE(Total Amount TM, DATEADD('Date'[Date], -1, MONTH))

2.3 创建[当期]和[前一期]的[差值]

Diff. = Total Amount TM - Total Amount PM

2.4 计算[差值]占[当期]量值的比例(YOY %)

YOY % = IF(
    ISBLANK(Total Amount TM),
    0,
    Diff. / Total Amount TM)

显示结果:


前期值.png

3.累计值(YTD)

3.1 创建[当期]量值的聚合(sum)

Total Amount TM= SUM(Sales[Amount])

3.2 创建累计(YTD)

YTD = CALCULATE(Total Amount TY, DATESYTD(DateTime[DateKey]))

显示结果:


累计值.png

三者一起显示的结果:

总.png

在这里使用YTD、QTD和MTD都没有太大差别,由于Power BI提供了良好的筛选聚合的功能,在YTD、QTD和MTD之间的转换实际上已经由Power BI替我们完成了。

你可能感兴趣的:(同比、环比、累计值在Power BI中的计算)