当前位置:网站首页>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 .

边栏推荐
- Baidu SEM bidding avoidance
- [datawhale202207] reinforcement learning: the foundation of reinforcement learning
- Data too long for column 'data' at row 1 and the garbled code caused by setting to longblob are solved. node-mysql
- (2022牛客多校二)L-Link with Level Editor I(动态规划)
- (2022 Niuke multi School II) l-link with level editor I (dynamic planning)
- Use abp Zero builds a third-party login module (4): wechat applet development
- Sword finger offer 45. arrange the array into the smallest number
- leetcode/二进制加法
- 【datawhale202207】强化学习:强化学习基础
- 【datawhale202207】强化学习:策略梯度和近端策略优化
猜你喜欢

Req.body in node.express is always undefind

Unity Animator动画与状态机

(Niuke multi School II) G-LINK with monotonic subsequence (construction question)
![[datawhale202207] reinforcement learning: the foundation of reinforcement learning](/img/1e/6ba657da14508854207aac51992ad8.png)
[datawhale202207] reinforcement learning: the foundation of reinforcement learning
![(16) [system call] track system call (3 rings)](/img/b0/011351361135fd9f8e2d0d31749f73.png)
(16) [system call] track system call (3 rings)

Use abp Zero builds a third-party login module (4): wechat applet development

【Node】服务端口被占用Error: listen EADDRINUSE: address already in use :::9000-如何关闭node启动的端口
![[ultra detailed diagram] FPN + mask RCNN](/img/ef/ddd62fe7e54074c134aa5ee4cc5840.png)
[ultra detailed diagram] FPN + mask RCNN

深度解析:2022年最火的商业模式链动2+1,是合法模式吗?
![(15)[驱动开发]过写拷贝](/img/1c/68dfff5671add1fe91567e4df34135.png)
(15)[驱动开发]过写拷贝
随机推荐
[datawhale202207] reinforcement learning: the foundation of reinforcement learning
target_ compile_ features specified unknown feature “cxx_std_14“ for target
Some interview questions collected
mysql 查询当前数据库下的表名
VBA common objects
Interlocked atom access series of functions
[daily practice] day (14)
Leetcode/ integer division
Context must be a dict rater solution
函数模板学习记录
[node] the service port is occupied error: listen eaddinuse: address already in use::: 9000- how to close the port started by node
JTAG debugging source level debugging of arm bare board debugging
R strange grammar summary
How does vscode enable multiple terminals? How to display horizontally?
MySQL queries the table name under the current database
(2022牛客多校)D-Link with Game Glitch(spfa)
“font/woff“ and “font/woff2“ in file “mime.types“
Baidu, Alibaba, Tencent, who fell first?
In depth analysis: is the hottest business model in 2022 linked by 2+1 a legal model?
Mysql database backup and recovery