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:思維導圖

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM