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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

SAMEPERIODLASTYEAR returns bank

Hello all, 

I am working on the AdventureWorks tables and trying to create a Sale Performance report. 

I have these three measures: 

 

Total Sale = SUMX(InternetSales, InternetSales[OrderQuantity]* RELATED('Product'[ListPrice]))
Total Cost = SUMX(InternetSales, InternetSales[OrderQuantity]*RELATED('Product'[StandardCost]))

And 

 

Total Profit = [Total Sale]- [Total Cost]

I want to make Total Profit LY and Total Sale LY, but it returns blank :

Total Profit LY = CALCULATE([Total Profit], SAMEPERIODLASTYEAR('Date'[FullDateAlternateKey]))

Q2.png

 

 

 

 

The date starts from 2011, so it is clear why the SAMEPERIODLASTYEAR() returns blank for 2011, but it shouldn't return blank for the other year, i.e. 2012, 2013 and 2014. 

 

 

I don't understand what is wrong?

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi

 

It's because your Slicer is using a calculated column and your measure for Same period last year is using another column.

The sameperiodlastyear function must use the same column that you are filtering with your slicer.

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi elahemeydani

 

Are you sure that the date column that you choose in the year is the same as [FullDateAlternateKey]?

If so can you perhaps provide a sample of the file?

 

Alternatively you can try this small workaround:

Profit SPLY :=
VAR MinLY =
EDATE ( MIN ( Date'[FullDateAlternateKey]' ); -12 )
VAR MaxLY =
EDATE ( MAX ( Date'[FullDateAlternateKey]' ); -12 )

RETURN
CALCULATE([Total Profit] ; FILTER(ALL('Date') ; 'Date'[FullDateAlternateKey]' <= MaxLY && Date'[FullDateAlternateKey]' >= MinLY))

Best Regards
KMW

Anonymous
Not applicable

Thank you for answering so quickly. 

 

W

hen I select no YEAR from the Slicer, it works just perfectly, but when a YEAR is selected, the LY values are blank  

Below you can see a screenshot of the Date table : 

 

Q3.png

Anonymous
Not applicable

Is the year date slicer also using the fulldatealternatekey column?
Anonymous
Not applicable

For the Slicer I used :

Year = YEAR('Date'[FullDateAlternateKey])

Now that  I replace the slicer with FullDateAlternateKey, it is working perfectly. 

 

But why ??Smiley Frustrated

Anonymous
Not applicable

Hi

 

It's because your Slicer is using a calculated column and your measure for Same period last year is using another column.

The sameperiodlastyear function must use the same column that you are filtering with your slicer.

Anonymous
Not applicable

Yes, now I understand what the problem is. 
Thank you for the explanation. 

 

I just wanted to have 'year' separately, and by using YEAR(date) function, the return value is an integer which can not be used in the SAMEPERIODLASTYEAR function. 

 

The only option that I have( or I can think of) is to add a calendar to my slicer like below: Q4.png

 

 

 

 

@Anonymous,

 

You may add ALL Function.

https://community.powerbi.com/t5/Desktop/Last-Fiscal-Year-Total-by-Month-DAX/m-p/224625#M99894

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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