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
shinney
Helper I
Helper I

Best way to filter on 2 dates?

Hello,

I'm trying to do my best to filter on 2 sets of Years, but having a hard time with the dax. Not sure if this is a CALCULATE, or FILTER? Essentially, I want to have it so when the Year filter is 2022, it will filter for both YearID = 2022 & BudgetYear = 2022.

 

In the example below, when Year = 2022, only Project A & Project F should show.

when Year = 2021, Project C & Project D should show

when Year = 2020, nothing should show, etc

 

YearIDBudgetYearTitle
20222022Project A
20222021Project B
20212021Project C
20212021Project D
20202021Project E
20222022Project F
20222023Project G

 

Thanks!

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

This is the approach you should follow.  Create calculated column formulas to make 2 date columns (YearID_Date and BedgetYear_Date) from the Year columns you have (the date could be day 1 and month 1 of those years).  Create a Calendar Table and write a calculated column formula to extract Year.  Create a relationship (Many to One and Single) from the YearID_Date column to the Date column of the Calendar Table.  Create a Table/matrix visual and drag Title there.  Create a Year slicer from the Calendar Table and select 2022.  Write this measure

Measure = calculate(countrows(Data),filter(Data,Data[YearID_date]=Data[BudgetYear_Date]))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-shex-msft
Community Support
Community Support

HI @shinney,

It sounds like you want to achieve the custom filter effect.

For this scenario, I'd like to suggest you write a measure formula to compare current value and both two fields value and return flag. Then you can use this formula on visual level filter to filter records.

Applying a measure filter in Power BI - SQLBI

Using the SELECTEDVALUE function in DAX - SQLBI

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi Xiaoxin,

 

Thanks for the reply. I'm still not really understanding how SELECTEDVALUE here would apply. Also, what do you mean by the return flag? None of the DAX measures I've tried remotely works

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.