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

Measure to get last 3 years

Hi all,

 

I have the below Year table and Year filter from Table1. I need CheckMeasure123 to put 1 next to 2018, 2019, 2020 when i select 2020 from the year filter.  

 

Any help around this is greatly appreciated. 

 

LP280388_0-1600280229920.png

 

1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

You will need two tables.

Create a simple table as slicer with first formula and create measure with second formula like below.

 

slicer = DISTINCT('Table'[year])

Measure = IF(SELECTEDVALUE('Table'[year])>SELECTEDVALUE('slicer'[year])-3&&SELECTEDVALUE('Table'[year])<=SELECTEDVALUE(slicer[year]),1,0)

 Result would be shown as below.

1.PNG2.PNG

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

5 REPLIES 5
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

You will need two tables.

Create a simple table as slicer with first formula and create measure with second formula like below.

 

slicer = DISTINCT('Table'[year])

Measure = IF(SELECTEDVALUE('Table'[year])>SELECTEDVALUE('slicer'[year])-3&&SELECTEDVALUE('Table'[year])<=SELECTEDVALUE(slicer[year]),1,0)

 Result would be shown as below.

1.PNG2.PNG

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
AllisonKennedy
Super User
Super User

Are these all in the same table? You will need two tables with Year column in each to make this work ideally- 1 table for the year filter. 1 table for the year in the table that is NOT related to the year filter table.

Is there any other requirement to your question? Once you have the relationships set up correctly, the measure part is easier. What if they select both 2019 and 2020 from the slicer?

Try using:
IF(NOT(SELECTEDVALUE(Table[Year]) IN VALUES(Slicer[Year])), 1, 0)

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

@AllisonKennedy Thanks.  Actually they are from the same table. Can this be possible without creating a new table for year alone?

Actually, on reading your post more carefully since you're looking for last three years, you could use DATEADD() function or DATESBETWEEN
I still recommend having a DimDate table and a Fact table in this case, but they can be related. https://excelwithallison.blogspot.com/2020/04/dimdate-what-why-and-how.html

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

@Anonymous  because you want to show items that are NOT selected, you need at least two tables that are NOT related. 

 

You could create the table using DAX: SlicerYearTable = VALUES(table[year]) or in Power Query. 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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.