当前位置:网站首页>你了解PowerBI中的去年同期吗
你了解PowerBI中的去年同期吗
2022-07-25 06:18:00 【PowerBI木小桼】
同比是分析指标中最基础的指标,但是你真的了解PowerBI中同比的实现吗?
我们先来看一下常见的我们书写同比的方式
sales = SUM( 'FactSales'[sales] )
sales.PY =
CALCULATE(
[sales],
DATEADD( 'DimDate'[Date], -1, YEAR )
)
sales.PY2 =
CALCULATE(
[sales],
SAMEPERIODLASTYEAR( 'DimDate'[Date] )
)
无论是使用DATEADD还是SAMEPERIODLASTYEAR都可以实现同比的计算,

一如上图所示,看起来没有任何问题,但是当我们把粒度细到天时再来看数据,2022年7月的数据只24号,可是上面两种方法在月维度时计算同比时计算的是2021年7月整月。

这时候很人很多可能会想到用月度至今计算就会正确了,是这样吗,我们来看一下
sales.MTD = TOTALMTD( [sales], 'DimDate'[Date] )
sales.MTD.PY =
CALCULATE(
[sales.MTD],
DATEADD(DimDate[Date], -1, YEAR )
)

会发现即便我们使用了MTD来计算去年同期,可是在月维度上仍然计算的是去年整月的数据,仔细观看数据会发现只需要在计算去年同期时如果当期未发生,就不计算,即因为当期数据只到2022.7.24,所以在计算去年同期时只需要计算到2021.7.24即可。
sales.PY3 =
VAR maxdate =
CALCULATE (
LASTNONBLANK ( 'DimDate'[Date], [sales] ),
ALL ( 'DimDate'[Date] )
)
RETURN
CALCULATE (
[sales],
SAMEPERIODLASTYEAR (
FILTER ( VALUES ( 'DimDate'[Date] ), 'DimDate'[Date] <= maxdate )
)
)

可以看到在月维度上去年同期只计算到了2021.7.24,并且当年未发生的日期上也不再显示值。
但是也会存在特殊情况,比如2020年2月是闰月有29天,2021年2月只有28天,所以在计算2021.2的去年同期时仍然会计算2020.2全月的数据,即计算到2020.2.29,但这正是我们需要的。

边栏推荐
- 【datawhale202207】强化学习:强化学习基础
- Xiaomi 12s UTRA Leica watermark generation online tool
- 【Node】服务端口被占用Error: listen EADDRINUSE: address already in use :::9000-如何关闭node启动的端口
- Seekbar属性参考
- 深度解析:2022年最火的商业模式链动2+1,是合法模式吗?
- “蔚来杯“2022牛客暑期多校训练营2 Link with Game Glitch (spfa找正负环)
- leetcode/二进制加法
- Common API of window
- JS how to delete an element without deleting its child elements
- Detailed annotation and analysis of start.s of uboot
猜你喜欢
![(15) [driver development] over written copy](/img/1c/68dfff5671add1fe91567e4df34135.png)
(15) [driver development] over written copy
![(14)[驱动开发]配置环境 VS2019 + WDK10 写 xp驱动](/img/90/0d94d26be8128d77de65919763fda5.png)
(14)[驱动开发]配置环境 VS2019 + WDK10 写 xp驱动

SAP FICO section III BDC and ltmc import S4 financial account

Unity 模型简化/合并 一键式插件

Qunhui NPV Suite (NPV server) Download
![[unity3d] ugui callback function](/img/6f/312e7f2cf76fa932e66c5ba0737219.png)
[unity3d] ugui callback function

Blocking Queue Analysis
![(14) [driver development] configuration environment vs2019 + wdk10 write XP driver](/img/90/0d94d26be8128d77de65919763fda5.png)
(14) [driver development] configuration environment vs2019 + wdk10 write XP driver

Data too long for column 'data' at row 1 and the garbled code caused by setting to longblob are solved. node-mysql

The code spell checker plug-in avoids some specific vocabulary errors "XXX": unknown word.cspell
随机推荐
Dry goods | training AI model can't find data? Collect 20 selected open source communities!
Ffmpeg notes (I) fundamentals of audio and video
Brief tutorial of vbs script syntax (1)
Typedef usage and template
Android interview question: why do activities rebuild ViewModel and still exist—— Jetpack series (3)
“font/woff“ and “font/woff2“ in file “mime.types“
What determines the "personality" of AI robots?
Introduction to the usage of explain and the meaning of result field in MySQL
10. Rendering Basics
深度解析:2022年最火的商业模式链动2+1,是合法模式吗?
嵌入式c语言开发之宏定义求两个数的最大值的使用技巧
Koa2 learning
4、 MFC toolbar, runtime class information mechanism, runtime creation mechanism
JS gets the text selected by the mouse and is in the selected state
Ceres solver version 1.14 and eigen3.2.9
(2022牛客多校)D-Link with Game Glitch(spfa)
【datawhale202207】强化学习:策略梯度和近端策略优化
Mechanism and principle of multihead attention and masked attention
HTB-Optimum
[daily practice] day (14)