cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
UCHKANA
New Member

DATEDIFF function with Filter

Hello all, 

I wanted to calulcate the date difference but with the filter. 

I wrote the following but it doesn't work. 

MEASURE = IF((max(OpportunityBase[StatusCode])=100000023), (DATEDIFF(TODAY(), FIRSTDATE('OpportunityBase'[Close By]), DAY)))

 Basicallly, I want to calculate the datediff between 'Close By' and Today only if Statuscode of the Close by equals 100000023. 

How can I solve this? Please help me 🙏

2 ACCEPTED SOLUTIONS
edhans
Super User
Super User

What are you doing with FIRSTDATE()? That is a time intelligence function.

 

This measure will functionally work, but I am not sure it will give you the results are are wanting. You should not use time intelligence functions to do date math. If you are using it intentionally knowing that it invokes context transition, that is fine, otherwise, use MIN() instead, or post back with more info.

Some Measure =
VAR varStartDate =
    TODAY()
VAR varEndDate =
    FIRSTDATE( 'OpportunityBase'[Close By] )
RETURN
    IF(
        MAX( OpportunityBase[StatusCode] ) = 100000023,
        DATEDIFF( varStartDate, varEndDate, DAY )
    )

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

Daryl-Lynch-Bzy
Solution Sage
Solution Sage

@UCHKANA 

 

Try the following to see if it works:


Measure Name = 
VAR _max = MAX( OpportunityBase[StatusCode] )
VAR _date = FIRSTNONBLANK( 'OpportunityBase'[Close By] , 1)
RETURN
IF ( _max = 100000023 ,
DATEDIFF( TODAY(), _date , DAY ) ,
BLANK()
)

 

View solution in original post

4 REPLIES 4
Daryl-Lynch-Bzy
Solution Sage
Solution Sage

@UCHKANA 

 

Try the following to see if it works:


Measure Name = 
VAR _max = MAX( OpportunityBase[StatusCode] )
VAR _date = FIRSTNONBLANK( 'OpportunityBase'[Close By] , 1)
RETURN
IF ( _max = 100000023 ,
DATEDIFF( TODAY(), _date , DAY ) ,
BLANK()
)

 

Omggg. It totally worked! Thank you soo much! ❤️

edhans
Super User
Super User

What are you doing with FIRSTDATE()? That is a time intelligence function.

 

This measure will functionally work, but I am not sure it will give you the results are are wanting. You should not use time intelligence functions to do date math. If you are using it intentionally knowing that it invokes context transition, that is fine, otherwise, use MIN() instead, or post back with more info.

Some Measure =
VAR varStartDate =
    TODAY()
VAR varEndDate =
    FIRSTDATE( 'OpportunityBase'[Close By] )
RETURN
    IF(
        MAX( OpportunityBase[StatusCode] ) = 100000023,
        DATEDIFF( varStartDate, varEndDate, DAY )
    )

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

And it worked too! Thank you so much! I appreciate it! ❤️

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors