POWER BI - 去年年份表达公式year(today())
去年:year(today())-1,例如今年是2021年,那么year(today())-1 = 2020年。
创建相关的年初、末的参数:
I've created (measures) for relative variable year start and end e.g.
This year
Var TY Start = Date(Year(Today()),01,31)
Var TY End = Date(Year(Today()),12,31)
Last Year
Var LY Start = Date(Year(Today())-1,01,31)
Var LY End = Date(Year(Today())-1,12,31)
Then I used the variables in the Calculate Measure:
LY Sales = Calculate(sum([sales]),
Datesbetween(Dates[Calender],
[Var LY Start], [Var LY End]
)
So to go 2 years back I created more variables for start and end and -2 of the year etc. This is working for me. I know there are probably alot cleaner and smarter ways of doing this, but this was a quick fix for me to create a variable relative to todays date.
ref:Solved: Basic previous year measure - Microsoft Power BI Community
power query:今年2021年份获取 思路:
获取当天日期
DateTime.Date(DateTime.LocalNow())
获取今年年份:Date.Year(DateTime.Date(DateTime.LocalNow()))
ref:Date.Year - PowerQuery M | Microsoft Docs
自定义列custom column也会用到power query:思维导图