Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Sameperiodlastyear, but only until the same date as this year

So earlier I posted a question because I can't get the KPI visual to work correctly and I still can't

https://community.powerbi.com/t5/Desktop/Can-t-get-the-KPI-visual-to-work-correctly/m-p/2184879

 

I've tried more than 30 calculations so far and I'm getting very close, but not quite there yet.

 

So first I'll expain what I want.

I want the KPI visual to display the total revenue of the current year (indicator)

RevenueYTD = TOTALYTD([Revenue],'Calendar'[Date],'Calendar'[Year]=YEAR(TODAY()))

 

And compare it to the total revenue of the previous year, but only for the exact same period of last year (goal / target). So for today that would mean only calculate the revenue of 01-01-2020 until 19-11-2020.

RevenueLYTD = TOTALYTD([Revenue],SAMEPERIODLASTYEAR('Calendar'[Date]),'Calendar'[Year]=YEAR(TODAY())-1)
The above function doesn't give me the result I want, because it sums the entire year 2020. I only want the same period of last year.
 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

After a little bit of puzzling I managed to make it work, thanks for the inspiration amitchandak

 

RevenueLYTD =

var _min = date(year(today())-1,1,1)

var _max = date(year(today())-1,month(today()),day(today()))

return TOTALYTD([Revenue],SAMEPERIODLASTYEAR('Calendar'[Date]),'Calendar'[Date] >= _min && 'Calendar'[Date] <= _max)

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

After a little bit of puzzling I managed to make it work, thanks for the inspiration amitchandak

 

RevenueLYTD =

var _min = date(year(today())-1,1,1)

var _max = date(year(today())-1,month(today()),day(today()))

return TOTALYTD([Revenue],SAMEPERIODLASTYEAR('Calendar'[Date]),'Calendar'[Date] >= _min && 'Calendar'[Date] <= _max)

amitchandak
Super User
Super User

@Anonymous , YTD and LYTD based on today, no filter selected

 

YTD Today=
var _min = date(year(today()),1,1)
var _day = today()
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Date] >=_min && 'Date'[Date] <= _day) )

LYTD =
var _min = date(year(today())-1,1,1)
var _max = date(year(today())-1,month(today()),day(today()))
var _day = datediff(_min, _max,day)+1
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year] = year(Today())-1 && 'Date'[Day of Year] <= _max))

 

 

////////////with Date elements in group by , like daily YTD
YTD Today=
var _min = date(year(today()),1,1)
var _day = today()
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Date] >=_min && 'Date'[Date] <= _day && 'Date'[Date] <=Max('Date'[Date] ) ) )

LYTD =
var _min = date(year(today())-1,1,1)
var _max = date(year(today())-1,month(today()),day(today()))
var _day = datediff(_min, _max,day)+1
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year] = year(Today())-1 && 'Date'[Day of Year] <= _max && 'Date'[Date] <= date(year(Max('Date'[Date] ))-1,month(Max('Date'[Date] )),day(Max('Date'[Date] )))))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

I don't have a [Day of Year] in my calender table yet. Can you help me with that?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.