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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

SAMEPERIODLASTYEAR returns no value for selected time period

I am currently trying to build a dynamic report where users can select a time period and see sales numbers for the current time period as well as the previous period. To assist users with this I have also tried to pre-define some time periods to make it easier to filter. My set up is as follows with three relevant tables for this report:

 

 

image.png

 

For DatePeriod I have used the following code to create pre-defined reporting periods: 

 

DatePeriod = UNION (   
   ADDCOLUMNS( SUMMARIZE( CALCULATETABLE('Dates' ; DATESBETWEEN('Dates'[Date];EOMONTH(TODAY();-2)+1;EOMONTH(TODAY();-1)) ); 'Dates'[Date]);"Period";"Previous Month")  ;
   ADDCOLUMNS( SUMMARIZE( CALCULATETABLE('Dates' ; DATESBETWEEN('Dates'[Date];EOMONTH(TODAY();-1)+1;EOMONTH(TODAY();0)) ); 'Dates'[Date]);"Period";"Current month")  ;
   ADDCOLUMNS( SUMMARIZE( CALCULATETABLE('Dates'); 'Dates'[Date]);"Period";"Overall") 
)

This is what the report looks like without a filter being set:

 

image.png

Looks as I would expect it to look. However if I set a filter, for example "Current Month", this happens: 

 

image.pngThe value for the previous time period is no longer being displayed. I should also add that if I use a direct filter on my Date table and select a period in there via the timeline or the relative date capabilities, the previous time period gets displayed properly. 

 

image.png

 Here is how Sales PTP is defined:

Sales PTP = CALCULATE(SUM(SalesCalculated[Sales Amount]);SAMEPERIODLASTYEAR(Dates[Date]))

I am assuming that my approach with pre-defined time periods is somehow not playing nice with the SAMEPERIODLASTYEAR() function. 

 

EDIT: I also tried this formula. The result was that Sales PTP displayed the same value as sales when a time period was selected.

Sales PTP = CALCULATE(SUM(SalesCalculated[Sales Amount]);FILTER(ALL(Dates[Date]);SAMEPERIODLASTYEAR(Dates[Date])))
1 REPLY 1
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

Could you please share some sample data and give the expected result?

 

Regards,

Jimmy Tao

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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