Forum Discussion
SAME PERIOD LAST YEAR
Hi All,
basic Question from my side.
HOW TO USE SAME PERIOD LAST YEAR ---- in ----- calculated columns ?
Hi vijay273162
If you are using dates from a fact table, try this way,
column = VAR _date = EDATE ( 'Table'[Date], -12 ) RETURN CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( ALL ( 'Table' ), 'Table'[Date] >= _date && 'Table'[Date] < EARLIER ( 'Table'[Date] ) ) )If you want to create measure, then try this
LY = CALCULATE(SUM('Table'[Sales]),SAMEPERIODLASTYEAR('Table'[Date]))Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.
11 Replies
- truptis
Community Champion
Hi vijay273162
SAMEPERIODLASTYEAR - Returns a table that contains a column of dates shifted one year back in time from the dates specified in date column.
Thus, you can't use it in the column.
you can achieve this using the below steps:
1- For the current date - create 1 concatenated column of date removing '/'. you can add a custom column which says:
Use CONCAT function : eg - =Concat(Month(Date),Year(Date))
2- For the last year's date - create another concatenated column
eg- Concat(Month(Date),year(Date)-1)
3- Return the values of sales by matching column 2(Concatenation of Last year's date) with Column 1(Concatenation of current date).If you need the exact DAX, then please share sample data with me.
If this helps, then please mark it as a solution and hit the thumbs up.
Regards,TruptiS
- AnonymousNot applicable
Perfect
- vijay273162
Helper III
Hi,
This is how I got the result for Same Period Last Year using calculated column
- v-xiaotang
Community Support
Hi vijay273162
If you are using dates from a fact table, try this way,
column = VAR _date = EDATE ( 'Table'[Date], -12 ) RETURN CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( ALL ( 'Table' ), 'Table'[Date] >= _date && 'Table'[Date] < EARLIER ( 'Table'[Date] ) ) )If you want to create measure, then try this
LY = CALCULATE(SUM('Table'[Sales]),SAMEPERIODLASTYEAR('Table'[Date]))Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.
- YoungLearning
Helper III
Is SUM necessary?
This answer looks wrong too, can someone educate me a little here? I was assuming it's SAMEPERIODLASTYEAR.
- vijay273162
Helper III
Then I will hide the previous year column
- Greg_Deckler
Community Champion
vijay273162 Well, my answer is not to. You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000
Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.
https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TITHW/m-p/434008 - vijay273162
Helper III
no not helpful
- vijay273162
Helper III
v-zhangti Could you help in this ?
- truptis
Community Champion
Please mark this as a solution if it worked for you so that other community members can find the solution quickly. Thanks.
Regards,
TruptiS
- IkalausFrequent Visitor
I have another solution for how to calculate last year same-month
Last year revenue = CALCULATE(SUM( 'table'[revenue]),FILTER('table','table'[month/date] = DATE( YEAR(TODAY()) - 1, MONTH(TODAY()), 01))