Forum Discussion
Subset of data
Hi, I am looking for a help on a used case I am working on. I have the following sample data and I want this measure to give the putput as mentioned below.
| Cust ID | Year | Score |
| 1 | 2019 | 23.45 |
| 1 | 2022 | 34.64 |
| 2 | 2021 | 18.9 |
| 2 | 2020 | 34.55 |
| 3 | 2021 | 55.78 |
| 5 | 2023 | 62.45 |
| 2 | 2022 | 67 |
| 5 | 2022 | 12.67 |
| 6 | 2020 | 37.63 |
| 6 | 2018 | 34.98 |
Output-if we pick cust id 1
| Cust ID | Year | Score |
| 1 | 2022 | 34.64 |
| 2 | 2021 | 18.9 |
| 2 | 2020 | 34.55 |
| 2 | 2022 | 67 |
| 3 | 2021 | 55.78 |
| 5 | 2022 | 12.67 |
| 6 | 2020 | 37.63 |
What I am looking for is, if a user select a customer ID (from a slicer), we should take the selected customer ID's max year and then we want to retrive only the rows where the Year is within 3 years from a given customer's maximum year.
Hope I am clear in articlulating my requirement year. I want to display this output on a table visual.
Thanks in advance,
SD
Hi SriDatta ,
Create a table with the customers ID for the slicer, then add the following measure:
Filter_Rows = VAR _YEARSELECTION = MAXX( FILTER( ALL('Table'), 'Table'[Cust ID] = SELECTEDVALUE('Customers Filter'[Cust ID]) ), 'Table'[Year] ) RETURN IF( SELECTEDVALUE('Table'[Year]) > _YEARSELECTION - 3 && SELECTEDVALUE('Table'[Year]) <= _YEARSELECTION, 1 )Now use this measure has a filter on the table and select is not blank.
1 Reply
- MFelixSuper User
Hi SriDatta ,
Create a table with the customers ID for the slicer, then add the following measure:
Filter_Rows = VAR _YEARSELECTION = MAXX( FILTER( ALL('Table'), 'Table'[Cust ID] = SELECTEDVALUE('Customers Filter'[Cust ID]) ), 'Table'[Year] ) RETURN IF( SELECTEDVALUE('Table'[Year]) > _YEARSELECTION - 3 && SELECTEDVALUE('Table'[Year]) <= _YEARSELECTION, 1 )Now use this measure has a filter on the table and select is not blank.