在日常分析中,用的比较多的是环比或者是同比的计算,我们先来看看最新日期日&月环比或者同比,
数据源比较简单,如图所示:
![d0f48d7a339114619d816428c36ea744.png](https://i-blog.csdnimg.cn/blog_migrate/448d4409f31fe18071c4a9d8521f5826.jpeg)
- 最新日期的日环比
我们知道环比公式是:今天销售额/昨天销售额-1
一般数据源刷新方式是T+1刷新,所以数据源中的最近日期是相对日期的昨天,创建一个计算字段【日环比】:
sum(if [日期]=dateadd('day',-1,today()) then [销售额] end )/
sum(if [日期]=dateadd('day',-2,today()) then [销售额] end )-1
如图所示:
![bcba0d85b9a7bfad22be148047d41b58.png](https://i-blog.csdnimg.cn/blog_migrate/c91b13831762e6ccb819a2ed548fb58d.jpeg)
将创建好的计算字段【日环比】拖拽至文本上,会显示对应的环比,如图所示:
2.最近的月环比
同样的方法,创建计算字段【月环比】:
sum(if [日期]= datetrunc('month',dateadd('month',-1,today())) then [销售额] end )/
sum(if [日期]=datetrunc('month',dateadd('month',-2,today())) then [销售额] end )-1
如图所示:
![3cddeaa7ce4d875de6819a5b78d2fec9.png](https://i-blog.csdnimg.cn/blog_migrate/3da871ea45420bb6d5ba26d185f4102a.jpeg)
3.月同比
创建一个计算字段【月同比】:
sum(if [日期]=datetrunc('month',dateadd('month',-1,today())) then [销售额] end)/
sum(if [日期]=datetrunc('month',dateadd('month',-1,dateadd('year',-1,today()))) then [销售额] end )-1
如图所示:
![035b88e41ccdd786ca147fc05cf1df53.png](https://i-blog.csdnimg.cn/blog_migrate/b2b846ad8be2620aea36eff89427e842.jpeg)