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
Anonymous
Not applicable

DAX MTD & Prior Year

Hi All,

 

I am trying to calcuate the count for the current year & month; 2020 Jan to April (current month) and also show the same period Jan to April but for last year 2019. I have created a date table and marked it as a date table.

 

Date =
ADDCOLUMNS (
CALENDAR (DATE(2000,1,1), DATE(2025,12,31)),
"DateAsInteger", FORMAT ( [Date], "YYYYMMDD" ),
"Year", YEAR ( [Date] ),
"Monthnumber", FORMAT ( [Date], "MM" ),
"YearMonthnumber", FORMAT ( [Date], "YYYY/MM" ),
"YearMonthShort", FORMAT ( [Date], "YYYY/mmm" ),
"MonthNameShort", FORMAT ( [Date], "mmm" ),
"MonthNameLong", FORMAT ( [Date], "mmmm" ),
"DayOfWeekNumber", WEEKDAY ( [Date] ),
"DayOfWeek", FORMAT ( [Date], "dddd" ),
"DayOfWeekShort", FORMAT ( [Date], "ddd" ),
"Quarter", "Q" & FORMAT ( [Date], "Q" ),
"YearQuarter", FORMAT ( [Date], "YYYY" ) & "/Q" & FORMAT ( [Date], "Q" )
)

 

which has a 1 to many relationship to my data table 'New Business' [Variation Issue Date]

 

Current Year DAX : 

Count YTD = CALCULATE(COUNT('New Business'[Count]), DATESYTD('New Business'[Variation Issue Date]))
returns the correct count of 8206.
 
Prior Year DAX:
target = 9952
Count PYTD = CALCULATE([Count YTD], SAMEPERIODLASTYEAR('Date'[Date])) returns same count as current year
Count PYTD = CALCULATE([Count YTD], SAMEPERIODLASTYEAR('New Business'[Variation Issue Date])) returns error Function 'SAMEPERIODLASTYEAR' expects a contiguous selection when the date column is not unique, has gaps or it contains time portion
Count PYTD = CALCULATE(TOTALMTD(COUNT('New Business'[Count]),'Date'[Date]), SAMEPERIODLASTYEAR('Date'[Date])) returns blank 
Count PYTD = CALCULATE(TOTALMTD(COUNT('New Business'[Count]),'New Business'[Variation Issue Date]), SAMEPERIODLASTYEAR('Date'[Date])) returns 2813
Count PYTD = CALCULATE([Count YTD], DATEADD('Date'[Date],-1, year)) returns 8206
Count PYTD = CALCULATE(count('New Business'[Count]), DATEADD('Date'[Date],-1, year)) returns 386804
 
I have tried a few different ways to do it and none of them work, so any help would be appreicated.
 
Thanks
10 REPLIES 10

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