Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
mgrayTCB
Helper IV
Helper IV

Filter for Common years in DAX

I cant get my head around how to do this... I want to filter the table for only the years that the projects have in common. I wont know how many projects are in the table or what the common years are. I just want the common years so I can add the rent values together and calculate annual yoy rent growth for properties that existed in those years.

 

Table  
Propertyrentyear
Project 1502020
Project 11002021
Project 11202022
Project 11102023
Project 11052024
Project 11252025
Project 11002026
project 26002021
project 25502022
project 25802023
project 25702024
project 24902025
project 38002021
project 38252022
project 38752023

 

 

I would want this result

Expected Result 
Propertyrentyear
project 38002021
project 38252022
project 38752023
project 26002021
project 25502022
project 25802023
Project 11002021
Project 11202022
Project 11102023
1 ACCEPTED SOLUTION

Sorry forgot to removefilters

 

Measure =

Var tbl=

Calculatetable(

Addcolumn(

Values(table[property]),

"@minYear", calculate( min( table[year] )),

"@maxYear", calculate( max( table[year] ))

),

Allselected()

)

Var minYear = MAXX( tbl, [@minYear])

Var maxYear = MINX( tbl, [@maxYear])

Var years =

Filter(

All( table[year] ),

Table[year] >=minYear &&

Table[year] <= maxYear

)

Return

If( selectedvalue( table[year] ) in years, 1)


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

View solution in original post

9 REPLIES 9
v-pgoloju
Community Support
Community Support

Hi @mgrayTCB,

Thank you for reaching out to the Microsoft Fabric Forum Community.

Also, a special thanks to @Deku and @Sahir_Maharaj  for the quick and helpful response.

Just following up to check if the solution shared by our Super User @Deku helped resolve your issue. If you're still facing difficulties or need further assistance, please let us know — we’re here to help!
If the response addressed your query, we kindly request you to mark it as Accepted Solution and click Yes if you found it helpful. This supports others in the community as well.

Best regards,
Prasanna Kumar

Sahir_Maharaj
Super User
Super User

Hello @mgrayTCB,

 

Can you please try this approach:

CommonYears =
VAR AllProjects = DISTINCT('Table'[Property])
VAR CommonYears =
    FILTER (
        VALUES('Table'[year]),
        CALCULATE (
            COUNTROWS (
                FILTER (
                    AllProjects,
                    CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Property] = EARLIER('Table'[Property]) && 'Table'[year] = EARLIER('Table'[year]) ) > 0
                )
            ) = COUNTROWS(AllProjects)
        )
    )
RETURN
    FILTER (
        'Table',
        'Table'[year] IN CommonYears
    )

 


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ About: https://sahirmaharaj.com/about.html
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Not sure why this approach is not working....

mgrayTCB_0-1744665520514.png

 

 

Deku
Super User
Super User

Measure =

Var tbl= Addcolumn(

Values(table[property]),

"@minYear", calculate( min( table[year] )),

"@maxYear", calculate( max( table[year] ))

)

Var minYear = MAXX( tbl, [@minYear])

Var maxYear = MINX( tbl, [@maxYear])

Var years = 

Filter(

Values( table[year] ),

Table[year] >=minYear &&

Table[year] <= maxYear 

)

Return

If( selectedvalue( table[year] ) in years, 1)

 

Add the is measure to filter pane of the visual and filter to 1


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

I am not following what this is supposed to do but it does not seem to work

mgrayTCB_1-1744662076809.png

 

mgrayTCB_0-1744662030768.png

 

Rows 6 and 7 are wrong. You want the max min year and the min max year.


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

What else am I missing... That did not change anything

mgrayTCB_0-1744664214859.png

 

Sorry forgot to removefilters

 

Measure =

Var tbl=

Calculatetable(

Addcolumn(

Values(table[property]),

"@minYear", calculate( min( table[year] )),

"@maxYear", calculate( max( table[year] ))

),

Allselected()

)

Var minYear = MAXX( tbl, [@minYear])

Var maxYear = MINX( tbl, [@maxYear])

Var years =

Filter(

All( table[year] ),

Table[year] >=minYear &&

Table[year] <= maxYear

)

Return

If( selectedvalue( table[year] ) in years, 1)


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

That worked. Although I still cant get my head around the logic.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.