Forum Discussion
Current Year and previous year
Hi Community,
I am having problem creating measure for below requirement. My data is like below.
| Year | Sales |
| 2018 | 400 |
| 2018 | 5 |
| 2019 | 4 |
| 2015 | 7 |
| 2016 | 4000 |
| 2014 | c |
| 2016 | 3 |
| 2017 | 47 |
| 2019 | 9 |
| 2018 | 4 |
| 2018 | 6 |
| 2019 | 7 |
| 2015 | 5 |
| 2016 | 7 |
| 2014 | 9 |
| 2016 | 1 |
| 2017 | 2 |
| 2019 | 8 |
| 2018 | 3 |
| 2018 | 48 |
| 2019 | 69 |
| 2015 | 47 |
| 2016 | 65 |
| 2014 | 48 |
And I have a slicer on Year column.
My requirement is to When ever the user click on a year it should should the the selected year value sales as Current year sales and previous year of the that selected year should be previuos year sales. Example like below.
If a user selects 2017 on the slicer then it should display 2017 sales as CY Sales and 2016 Sales as PY Sales. If a If a user selects 2018 on the slicer then it should display 2018 sales as CY Sales and 2017 Sales as PY Sales.
Please help me.
Thank.
Hi Anonymous ,
New a Year dimension table, and keep it to be unrelated to source data table. Add [Year] from this dimension table into slicer.
Year dimension = VALUES('Yearly sales'[Year])Add [Year] from data table and below measures into table visual.
CY sales = IF ( SELECTEDVALUE ( 'Yearly sales'[Year] ) = SELECTEDVALUE ( 'Year dimension'[Year] ), CALCULATE ( SUM ( 'Yearly sales'[Sales] ), FILTER ( ALLSELECTED ( 'Yearly sales' ), 'Yearly sales'[Year] = SELECTEDVALUE ( 'Year dimension'[Year] ) ) ) ) PY sales = IF ( SELECTEDVALUE ( 'Yearly sales'[Year] ) = SELECTEDVALUE ( 'Year dimension'[Year] ), CALCULATE ( SUM ( 'Yearly sales'[Sales] ), FILTER ( ALLSELECTED ( 'Yearly sales' ), 'Yearly sales'[Year] = SELECTEDVALUE ( 'Year dimension'[Year] ) - 1 ) ) )Best regards,
Yuliana Gu
4 Replies
- Greg_Deckler
Community Champion
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 - v-yulgu-msft
Microsoft Employee
Hi Anonymous ,
New a Year dimension table, and keep it to be unrelated to source data table. Add [Year] from this dimension table into slicer.
Year dimension = VALUES('Yearly sales'[Year])Add [Year] from data table and below measures into table visual.
CY sales = IF ( SELECTEDVALUE ( 'Yearly sales'[Year] ) = SELECTEDVALUE ( 'Year dimension'[Year] ), CALCULATE ( SUM ( 'Yearly sales'[Sales] ), FILTER ( ALLSELECTED ( 'Yearly sales' ), 'Yearly sales'[Year] = SELECTEDVALUE ( 'Year dimension'[Year] ) ) ) ) PY sales = IF ( SELECTEDVALUE ( 'Yearly sales'[Year] ) = SELECTEDVALUE ( 'Year dimension'[Year] ), CALCULATE ( SUM ( 'Yearly sales'[Sales] ), FILTER ( ALLSELECTED ( 'Yearly sales' ), 'Yearly sales'[Year] = SELECTEDVALUE ( 'Year dimension'[Year] ) - 1 ) ) )Best regards,
Yuliana Gu
- AnonymousNot applicable
Hello v-yulgu-msft,
Your formula is working but not giving any results. i would like to find YTD also for CY and PY based on selected year(i have a period column also).
Thanks
- AnonymousNot applicable
Hi Yuliana Gu,
I'm also facing almost same situation as paruchuri447 mentioned below. But i need to filter values according to the slicer. suppose if i selecte 2019 as year from YEAR slicer, then i should get 2016,2017,2018 sales. this feature i implmented, but i couldn't achieve prioryear sales for all those years.
sturcture should be as:
category 2016 2017 2018
CY CY PY CY PY
c1 100 200 100 300 200
c2 20 50 20 80 50
my matrix should look like this, 2018 py should get 2017 CY value. i tried with the process below, but i couldnot acheive the result. the PY looks blank for me always. can you provide me any idea for this?
thanzz in advance..