Forum Discussion
ATO23
4 years agoFrequent Visitor
Add Previous Period (year) based on a custom date range selection
Good morning! We are dealing with a problem when we try to add the preivous period sales (year) when we select a date from a date range. So, the first step was add a table to identify de date r...
- Anonymous4 years ago
Hi ATO23 ,
I created some data:
Here are the steps you can follow:
1. Create measure.
Flag = var _select=SELECTEDVALUE('Period'[RelativeDate]) var _date=CALCULATE(MAX('Period'[Date]),FILTER(ALL(Period),'Period'[RelativeDate]=_select)) return IF( AND( MAX('Table'[Year])=YEAR(_date),MAX('Table'[Month])=MONTH(_date))||AND(MAX('Table'[Year])=YEAR(_date)-1,MAX('Table'[Month])=MONTH(_date)) ,1,0)Measure = SUMX( FILTER( ALLSELECTED('Table'),'Table'[Year]=MAX('Table'[Year])&&'Table'[Month]=MAX('Table'[Month])),[amount])2. Place [Flag]in Filters, set is=1, apply filter.
3. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
amitchandak
Super User
4 years agoATO23 , Not very clear. But you can get previous year using Date table like
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),SAMEPERIODLASTYEAR('Date'[Date]))
week Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-364,DAY))