cancel
Showing results for
Did you mean:
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

 YearID BudgetYear Title 2022 2022 Project A 2022 2021 Project B 2021 2021 Project C 2021 2021 Project D 2020 2021 Project E 2022 2022 Project F 2022 2023 Project G

Thanks!

3 REPLIES 3
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
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.
Helper I

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

Announcements

#### Power BI T-Shirt Design Challenge 2023

Submit your creative T-shirt design ideas starting March 7 through March 21, 2023.

#### Power BI March 2023 Update

Find out more about the March 2023 update.

#### March 2023 Events

Find out more about the online and in person events happening in March!

Top Solution Authors
Top Kudoed Authors