cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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.

2 ACCEPTED SOLUTIONS
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 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
Resident Rockstar

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()      )`

4 REPLIES 4
Resident Rockstar

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()      )`

New Member

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

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 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
New Member

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

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

#### Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors
Top Kudoed Authors