我的個(gè)人博客:https://lixiaohui.live
0. 一些名詞的解釋
0.1 解釋
名詞 | 中文名詞 | 意思 |
---|---|---|
YOY | 同比增長(zhǎng)率 | Year Over Year: 按年度計(jì)的增長(zhǎng)率 |
MOM | 環(huán)比增長(zhǎng)率 | Month Over Month: 按月度計(jì)的增長(zhǎng)率 |
YTD | 年累計(jì) | Year to Date: 指年初至當(dāng)前日期(不含今日)累計(jì) |
QTD | 季累計(jì) | Quarter to Date: 季度初至今累計(jì) |
MTD | 月累計(jì) | Month to Date: 月初至今累計(jì) |
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月兩個(gè)時(shí)段的數(shù)據(jù)進(jìn)行對(duì)比殴俱。
(MOM)環(huán)比:14年4月和14年3月兩個(gè)相鄰時(shí)間段的數(shù)據(jù)進(jìn)行對(duì)比养交。
假如今天是2017年12月3號(hào)...
(YTD)年累計(jì):YTD將計(jì)算從2017年1月1號(hào)到2017年12月3號(hào)量值的總計(jì)易结。
(QTD)季累計(jì):QTD將計(jì)算從2017年9月1號(hào)到2017年12月3號(hào)量值的總計(jì)枕荞。
(MTD)月累計(jì):MTD將計(jì)算從2017年12月1號(hào)到2017年12月3號(hào)量值的總計(jì)柜候。
DAX 語(yǔ)法參考鏈接:MSDN。
學(xué)習(xí)資料來(lái)自于Youtube:這里躏精。
1. 同比
1.1 創(chuàng)建[當(dāng)期]量值的聚合(sum
)
Total Amount TY= SUM(Sales[Amount])
1.2 創(chuàng)建[上一期]量值的聚合(sum
)
Total Amount LY= CALCULATE(Total Amount TY, SAMEPERIODLASTYEAR(Date[Datekey]))
1.3 創(chuàng)建[當(dāng)期]和[上一期]的[差值]
Diff. = Total Amount TY - Total Amount LY
1.4 計(jì)算[差值]占[當(dāng)期]量值的比例(YOY %
)
YOY % = IF(
ISBLANK(Total Amount TY),
0,
Diff. / Total Amount TY)
顯示結(jié)果:
2.環(huán)比
2.1 創(chuàng)建[當(dāng)期]量值的聚合(sum
)
Total Amount TM= SUM(Sales[Amount])
2.2 創(chuàng)建[前一期]量值的聚合(sum
)
Total Amount PM = CALCULATE(Total Amount TM, DATEADD('Date'[Date], -1, MONTH))
2.3 創(chuàng)建[當(dāng)期]和[前一期]的[差值]
Diff. = Total Amount TM - Total Amount PM
2.4 計(jì)算[差值]占[當(dāng)期]量值的比例(YOY %
)
YOY % = IF(
ISBLANK(Total Amount TM),
0,
Diff. / Total Amount TM)
顯示結(jié)果:
3.累計(jì)值(YTD
)
3.1 創(chuàng)建[當(dāng)期]量值的聚合(sum
)
Total Amount TM= SUM(Sales[Amount])
3.2 創(chuàng)建累計(jì)(YTD
)
YTD = CALCULATE(Total Amount TY, DATESYTD(DateTime[DateKey]))
顯示結(jié)果:
三者一起顯示的結(jié)果:
在這里使用YTD渣刷、QTD和MTD都沒(méi)有太大差別,由于Power BI提供了良好的篩選聚合的功能矗烛,在YTD辅柴、QTD和MTD之間的轉(zhuǎn)換實(shí)際上已經(jīng)由Power BI替我們完成了。