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

Sameperiodlastyear is giving me the total sales of last year instead of for the given time period

Hello Community,

Hope your all well.

 

So im currently working on income report for my company. I have calculated the total income and would now like to calculate the total income for the same period last year.Where my problem lies in is the fact that whenever I try to do the dax measure sameperiodlastyear it gives me the total income of last year instead of narrowing it down to the date filter I have selected.

 

For reference my total income is calculated using the following measure:

Deckunsbeitrag =
SUMX(
'BES DE KOELN$VK-Umsatz Details', 'BES DE KOELN$VK-Umsatz Details'[DB (MW)]
)

The sameperiodlastyear measure is the following:

Deckunsbeitrag LY =
CALCULATE(
[Deckunsbeitrag],
SAMEPERIODLASTYEAR(Datumstabelle[Date])
)

I then have a date filter which I put into a slicer on the dates ranging from the 01.01.21 to the 10.03.21.Like I previously explained the sameperiodlastyear measure takes the total income of the whole year instead of looking for the total income in the time period of 01.01.20 to the 10.03.20. Again for reference I do have a date table and use it so I'm very confused as to why I'm getting the total income of last year instead of getting it fo the given time period that I filter on on that page.

 

Any help would be greatly appreciated and thank you all a lot .

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous ,

Please use date table for this and use one of the two

 

Deckunsbeitrag LY =
CALCULATE(
[Deckunsbeitrag],
SAMEPERIODLASTYEAR(Date[Date])
)

 

 

Deckunsbeitrag LY =
CALCULATE(
[Deckunsbeitrag],
dateadd(Date[Date],-1,year)
)

Anonymous
Not applicable

Hi @amitchandak thanx so much for the quick reply !! 

 

I have already used both measures and they still give the total income for the whole year instead narrowing it down to the given time period for example 01.01.20 to 10.03.20. Is there any way I can add to the measure that it takes the previous year of the date filter which i added as a slicer to the page ?

 

Thanx again for our quick reply and help 

 

@Anonymous , Try like

 

1 year back =
var _max1 = maxx(allselected(Date), Date[Date])
var _min1 = minx(allselected(Date), Date[Date])
var _max = date(year(_max1)-1, month(_max), day(_max))
var _min = date(year(_min1)-1, month(_min1), day(_min1))

return
CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date] >= _min && 'Date'[Date] <= _max) )

Anonymous
Not applicable

Hi @amitchandak thanx again for the quick reply. I am still getting the same results (showing me the total income for last year and is ignoring the date filter that's on the page )

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