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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
anee123
Helper I
Helper I

Sameperiod last year gives different results with different date tables

 Hi,

 

I have date range from Jan 1 2020 till Dec 31 2021.... when the date is 23/1/2021(today) I should see distinct count of 2021 (Jan1-jan23 2021) and compare to prev year(Jan1 2020- Jan 23 2021).... when the month slicer is feb, mar or any other month apart from Jan.. the YTD should be 0 because it does not have data after Jan 23 2021 but for prev year feb 2020 has data and pytd should show data. I am able to achieve this using different date tables and using same period last year.

 

I want to achieve this with the Activation Date field present in sheet1 data instead of creating a seperate date field, I am getting partial output but some of the cases, its throwing error due to dates discontinuity. I used MAX and min of the date and created a date table but that gives data from 2019 till date, I want to avoid 2019 data while selecting, I don't want to use visual level filters but instead in dax. in the max min table the date range of activation date should be from 1-jan-2020 till 31-dec-2021.

 

Please find the pbix file below and the formula used,PYTD3 is giving me correct result which I want to achieve this using sheet1 activation date column and Maxmindatetable date column.

 

YTD = CALCULATE(DISTINCTCOUNT(Sheet1[ID]),DATESBETWEEN('CalendarDatetable'[Date],date(2021,01,01),date(2021,12,31)))

PYTD1 = CALCULATE(DISTINCTCOUNT(Sheet1[ID]),SAMEPERIODLASTYEAR('Maxmindatetable'[Date]))

PYTD2 = CALCULATE(DISTINCTCOUNT(Sheet1[ID]),SAMEPERIODLASTYEAR(Sheet1[Activation Date]))

PYTD3 = CALCULATE(DISTINCTCOUNT(Sheet1[ID]),SAMEPERIODLASTYEAR(CalendarDatetable[Date]))

 

https://drive.google.com/file/d/1I-VmtFK-XQU6-N1ijt8awAVzTUkxa5Er/view?usp=sharing

2 REPLIES 2
Anonymous
Not applicable

Hello @anee123 
You can refer to this link 

lbendlin
Super User
Super User

That's not how SAMEPERIODLASTYEAR works. It will always use complete periods. If you want YoYTD logic you need to add that filter yourself.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors