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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

SAMEPERIODLASTYEAR not working as expected

My data is coming from an Access DB.

 

All these formulas worked fine I believed:

Total Sales = CALCULATE(SUM(raw[Value]),FILTER(raw,raw[Online/TE]="Online" && raw[Value/Volume]="Value")) 
Total Sales YTD = TOTALYTD(raw[Total Sales],raw[Date])
Total Sales YTD Last Year = CALCULATE([Total Sales YTD], SAMEPERIODLASTYEAR(raw[Date])) 
 
However - I tried to do drilldown and got this error relating to contiguos dates.  Therefore I added in a separate calendar file - generating data from the file I am using and linked them with a 1-Many relationship:
DimDate = ADDCOLUMNS(CALENDAR(
DATE(YEAR(MIN(raw[Date])), 1, 1),
DATE(YEAR(MAX(raw[Date])), 12, 1)), "DateAsInteger", FORMAT ( [Date], "YYYYMMDD" ), "Year", YEAR ( [Date] ), "MonthNo", FORMAT ( [Date], "MM" ), "YearMonthNo", FORMAT ( [Date], "YYYY/MM" ), "YearMonth", FORMAT ( [Date], "YYYY/mmm" ), "MonthShort", FORMAT ( [Date], "mmm" ), "MonthLong", FORMAT ( [Date], "mmmm" ), "WeekNo", WEEKDAY ( [Date] ), "WeekDay", FORMAT ( [Date], "dddd" ), "WeekDayShort", FORMAT ( [Date], "dddd" ), "Quarter", "Q" & FORMAT ( [Date], "Q" ), "YearQuarter", FORMAT ( [Date], "YYYY" ) & "/Q" & FORMAT ( [Date],"Q" )
)
 This also seems to work fine. 
 
But now comes the problem - the formulas that were working for last year year-to-date now show the whole year instead of year-to-date?? 
 
Total Sales YTD Last Year = CALCULATE([Total Sales YTD], SAMEPERIODLASTYEAR(DimDate[Date].[Date]))
 
Any ideas why this is not working?  
 
2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Is this problem sloved? 

If it is sloved, could you kindly accept it as a solution to close this case?

If not, please let me know.

 

Best Regards

Maggie

v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create a calendar table as below, change the "Date" column to "Date" format(originally, it is of "datetime“ format), then create a relationship between tables.

DimDate =
ADDCOLUMNS (
    CALENDARAUTO (),
    "DateAsInteger", FORMAT ( [Date], "YYYYMMDD" ),
    "Year", YEAR ( [Date] ),
    "MonthNo", FORMAT ( [Date], "MM" ),
    "YearMonthNo", FORMAT ( [Date], "YYYY/MM" ),
    "YearMonth", FORMAT ( [Date], "YYYY/mmm" ),
    "MonthShort", FORMAT ( [Date], "mmm" ),
    "MonthLong", FORMAT ( [Date], "mmmm" ),
    "WeekNo", WEEKDAY ( [Date] ),
    "WeekDay", FORMAT ( [Date], "dddd" ),
    "WeekDayShort", FORMAT ( [Date], "dddd" ),
    "Quarter", "Q" & FORMAT ( [Date], "Q" ),
    "YearQuarter", FORMAT ( [Date], "YYYY" ) & "/Q"
        & FORMAT ( [Date], "Q" )
)

 

Create measures in your "raw" table

Total Sales =
CALCULATE (
    SUM ( raw[Value] ),
    FILTER ( raw, raw[Online/TE] = "Online" && raw[Value/Volume] = "Value" )
)
Total Sales YTD =
TOTALYTD ( raw[Total Sales], DimDate[Date] )

Total Sales YTD Last Year =
CALCULATE ( [Total Sales YTD], SAMEPERIODLASTYEAR ( DimDate[Date] ) )

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 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.