当前位置:网站首页>Do you know the same period last year in powerbi
Do you know the same period last year in powerbi
2022-07-25 06:20:00 【Powerbi muxiaofen】
Year on year is the most basic index in the analysis index , But you really know PowerBI Year on year implementation ?
Let's first look at the common way we write year-on-year
sales = SUM( 'FactSales'[sales] )
sales.PY =
CALCULATE(
[sales],
DATEADD( 'DimDate'[Date], -1, YEAR )
)
sales.PY2 =
CALCULATE(
[sales],
SAMEPERIODLASTYEAR( 'DimDate'[Date] )
)
Whether to use DATEADD still SAMEPERIODLASTYEAR Can achieve year-on-year calculation ,

As shown in the above figure , There seems to be no problem , But when we refine the granularity to days, we will look at the data ,2022 year 7 Monthly data only 24 Number , However, the above two methods calculate the month dimension and the year-on-year dimension 2021 year 7 The whole month .

At this time, many people may think that the monthly to date calculation will be correct , Is that right , Let's take a look
sales.MTD = TOTALMTD( [sales], 'DimDate'[Date] )
sales.MTD.PY =
CALCULATE(
[sales.MTD],
DATEADD(DimDate[Date], -1, YEAR )
)

You will find that even if we use MTD To calculate the same period last year , However, in the monthly dimension, the data of the whole month of last year is still calculated , If you look at the data carefully, you will find that you only need to calculate the same period last year if it does not happen in the current period , It doesn't count , That is, the current data only arrive 2022.7.24, So when calculating the same period last year, you only need to calculate 2021.7.24 that will do .
sales.PY3 =
VAR maxdate =
CALCULATE (
LASTNONBLANK ( 'DimDate'[Date], [sales] ),
ALL ( 'DimDate'[Date] )
)
RETURN
CALCULATE (
[sales],
SAMEPERIODLASTYEAR (
FILTER ( VALUES ( 'DimDate'[Date] ), 'DimDate'[Date] <= maxdate )
)
)

It can be seen that in the month dimension, the same period last year only calculated 2021.7.24, And the value is no longer displayed on the date that does not occur in the current year .
But there will also be special circumstances , such as 2020 year 2 Month is a leap month 29 God ,2021 year 2 Month only 28 God , So it's calculating 2021.2 In the same period last year, it will still be calculated 2020.2 Monthly data , That is, calculate to 2020.2.29, But this is exactly what we need .

边栏推荐
- (2022牛客多校二)K-Link with Bracket Sequence I(动态规划)
- Amazoncaptcha 95%成功率绕过亚马逊IP验证码
- What projects can make money online? Is it reliable to be we media?
- The code spell checker plug-in avoids some specific vocabulary errors "XXX": unknown word.cspell
- The most comprehensive multi-threaded application tutorial - summary in detail
- 【Jailhouse 文章】Base Architectures for virtual-physical computing(2018)
- Use abp Zero builds a third-party login module (4): wechat applet development
- Sword finger offer 36. binary search tree and bidirectional linked list
- 【Unity3D】UGUI回调函数
- ARM裸板调试之JTAG调试源码级调试
猜你喜欢
![[QT] solve the problem of Chinese garbled code output from QT console](/img/09/8af91d2a0327bd1d3c7b64f2b8185f.png)
[QT] solve the problem of Chinese garbled code output from QT console
![[datawhale202207] reinforcement learning: strategy gradient and near end strategy optimization](/img/4e/aabc603e47977503a4bcc5d07b4c61.png)
[datawhale202207] reinforcement learning: strategy gradient and near end strategy optimization

Data too long for column 'data' at row 1 and the garbled code caused by setting to longblob are solved. node-mysql
![[reprint] pycharm packages.Py program as executable exe](/img/9c/02a967fb08ca54bb742cf69c4578a7.png)
[reprint] pycharm packages.Py program as executable exe

(2022牛客多校)D-Link with Game Glitch(spfa)

Pdf snapshot artifact
![(15) [driver development] over written copy](/img/1c/68dfff5671add1fe91567e4df34135.png)
(15) [driver development] over written copy

(Niuke multi School II) G-LINK with monotonic subsequence (construction question)

SAP FICO 第三节 BDC和LTMC导入S4财务科目

你了解PowerBI中的去年同期吗
随机推荐
Unity 模型简化/合并 一键式插件
leetcode/二进制加法
Case ---- how efficient is the buffer stream compared with the ordinary input stream and output stream?
10. Rendering Basics
How to troubleshoot the problem of too many inodes
Binary search tree (day 75)
R strange grammar summary
Android interview question: why do activities rebuild ViewModel and still exist—— Jetpack series (3)
[daily practice] day (14)
有什么能在网上挣钱的项目啊?做自媒体靠谱吗?
Review of some classic exercises of arrays
UML modeling tools Visio, rational rose, powerdesign
Define usage method and template
Date (day 76)
都说ScreenToGif是GIF录制神器,却不知其强大之处远不在此
In depth analysis: is the hottest business model in 2022 linked by 2+1 a legal model?
New developments in Data Governance: what is the impact of the EU's Data Governance Research Report on China
VBA common objects
(16) [system call] track system call (3 rings)
(Niuke multi school I in 2022) i-chiitoitsu (expected DP)