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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.