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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Adding a Filter to IF in DAX

I'm trying to add a filter to the following:

 

IF(MAX ('Table'[Date1]) <= TODAY() ||
    MAX ('Table'[Date2]) <= TODAY() ||
    MAX ('Table'[Date3]) <= TODAY() ||
    MAXX ('Table', 'Table'[Approval]) <> "Yes",
    1, 0)

I need a filter on the Date3 line so that 'Table'[Type] = "TypeA" and I cannot figure out how to do it. 

It feels like this should be really simple! Can anyone help please?
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for the help everyone. I have just solved my problem by creating a separate measure for the Type:

Filter TypeA = IF( CONTAINS( 'Table', 'Table[Type], "TypeA", 1, 0)

Then added that to my original measure, so it reads:

IF(MAX ('Table'[Date1]) <= TODAY() ||
    MAX ('Table'[Date2]) <= TODAY() ||
    MAX ('Table'[Date3]) <= TODAY() && [Filter TypeA] = 1||
    MAXX ('Table''Table'[Approval]) <> "Yes",
    1, 0)


I'm sure it's not the most elegant way to do it, but it works. 

View solution in original post

9 REPLIES 9
WishAskedSooner
Continued Contributor
Continued Contributor

The short answer is: Yes, it makes sense. The long answer is, No, because all those conditions make my head hurt. The only tip I have is adding an ISBLANK() condition to your list of conditions. For example:

 

OR(MAX ('Table'[Date1]) <= TODAY(), ISBLANK('Table'[Date1]))

 

Maybe that will get you want you need, but this really goes beyond PowerBI and DAX and falls into the realm of overly bespoke requirements.

Anonymous
Not applicable

Hi @Anonymous ,

 

Here I think you need to understand that Type =A is a juxtaposition to the computational logic on Date3 that needs to be satisfied at the same time, and if in the case of a more complex relationship, you can use OR() as well as AND() function to help sort out the computational logic.

I think  Ritaf1983 needs to update the measure, although the results returned are correct, Date2 is used where Date3 should have been used.

You can try code as below to create a measure.

Measure:

 

Flag = 
VAR _DATE1 =
    SELECTEDVALUE ( 'Table'[Date1] )
VAR _DATE2 =
    SELECTEDVALUE ( 'Table'[Date2] )
VAR _DATE3 =
    SELECTEDVALUE ( 'Table'[Date3] )
VAR _Type =
    SELECTEDVALUE ( 'Table'[Type] )
VAR _Approval =
    SELECTEDVALUE ( 'Table'[Approval] )
VAR _RESULT =
    IF (
        OR ( _DATE1 < TODAY (), ISBLANK ( _DATE1 ) )
            || OR ( _DATE2 < TODAY (), ISBLANK ( _DATE2 ) )
            || AND ( OR ( _DATE3 < TODAY (), ISBLANK ( _DATE3 ) ), _Type = "A" )
                || _Approval <> "Yes",
        1,
        0
    )
RETURN
    _RESULT

 

Result is as below.

vrzhoumsft_1-1730081971398.png

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks for the help everyone. I have just solved my problem by creating a separate measure for the Type:

Filter TypeA = IF( CONTAINS( 'Table', 'Table[Type], "TypeA", 1, 0)

Then added that to my original measure, so it reads:

IF(MAX ('Table'[Date1]) <= TODAY() ||
    MAX ('Table'[Date2]) <= TODAY() ||
    MAX ('Table'[Date3]) <= TODAY() && [Filter TypeA] = 1||
    MAXX ('Table''Table'[Approval]) <> "Yes",
    1, 0)


I'm sure it's not the most elegant way to do it, but it works. 
WishAskedSooner
Continued Contributor
Continued Contributor

Try this:

 

IF(MAX ('Table'[Date1]) <= TODAY() ||
    MAX ('Table'[Date2]) <= TODAY() ||
    AND(MAX ('Table'[Date3]) <= TODAY(), 'Table'[Type] = "TypeA") ||
    MAXX ('Table''Table'[Approval]) <> "Yes",
    1, 0)
Ritaf1983
Super User
Super User

Hi @Anonymous 

Please provide a workable sample data and your expected result from that. It is hard to figure out what you want to achieve from the description alone.  

https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile
Anonymous
Not applicable

IDDate1Date2Date3ApprovalType
10012/07/202427/12/202427/12/2024YesA
10127/12/202427/12/202427/12/2024YesA
10227/12/202412/07/2024 YesB
10327/12/202427/12/2024 YesB
10412/07/202427/12/202427/12/2024NoA
10527/12/202427/12/2024 YesA

 

I'm trying to return an value of 1 when :
Date1 is in the past or blank OR
Date2 is in the past or blank OR
Date3 is in the past or blank and Type is A OR
Approval is Yes

In the example above, I would expect the following to happen:
ID100 would return value of 1 becasue Date1 is in the past
ID101 would return value of 0 because all dates are in the future and Approval is Yes
ID102 would return value of 1 because Date2 is in the past
ID103 would return value of 0 because Date3 is blank but Type is B
ID104 would return value of 1 because Date1 is in the past and Approval is No
ID105 would return value of 1 because Date3 is blank and Type is A

Hope that makes more sense! Thank you.

Hi @Anonymous 
According to the wanted result the formula is ,

Flag =
if(SELECTEDVALUE('Table'[Date1])<TODAY() ||
ISBLANK(SELECTEDVALUE('Table'[Date1]))||
SELECTEDVALUE('Table'[Date2])<TODAY() ||
ISBLANK(SELECTEDVALUE('Table'[Date2]))||
(SELECTEDVALUE('Table'[Date2])<TODAY() ||
ISBLANK(SELECTEDVALUE('Table'[Date3]))&& SELECTEDVALUE('Table'[Type])="A" &&
SELECTEDVALUE('Table'[Approval])="Yes"),1,0)
But note that approval "YES" is with and anf not with or according to :
"ID101 would return value of 0 because all dates are in the future and Approval is Yes"

Ritaf1983_0-1729862176537.png

The pbix is attached

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile
Uzi2019
Super User
Super User

Hi @Anonymous 

 

Can you try this on date 3

Max value =
IF(MAX('Calendar'[Date])<=TODAY(),MAXX(FILTER(Table,Table[Brand]="ABCD"),1),0)
 
I hope I answered your question!
 
 
Don't forget to give thumbs up and accept this as a solution if it helped you!!!
Anonymous
Not applicable

Thanks, but that didn't work. Everything returned a value of 1. 

More than willing to admit that's it's because I've done something wrong than there being any problem with your solution.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.