Skip to main content
cancel
Showing results for 
Search instead 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

Reply
Herchris7172
Regular Visitor

DAX | Date Diff

Hello Team

Need your help on the below 

I have 2 Tables, one includes Dates, Revised Due Date 

Herchris7172_0-1720128762150.png

Second is a Calender table Used to define my Selected-Date=SelectedValue(Calender[Date])

 

Need to Calculate the Date Diff. If Revised Due Date is Blank then DateDiff is between Date and Selected Date otherwise it will be Revised Due Date and Selected Date.

 

Am using a Column with sumx but only managing to get the sum of the DateDiff with Revised Due Date 

Column = SUMX(Sheet1,IF(ISBLANK(Sheet1[Revised Due Date]),DATEDIFF(Sheet1[Dates ],Sheet1[Selected-Date],MONTH),DATEDIFF(Sheet1[Dates ],Sheet1[Revised Due Date],MONTH)))
 
Any Advice
 
1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Herchris7172 ,

 

Here are the steps you can follow:

1. Create measure.

Measure =
var _select=SELECTEDVALUE('Calender'[Date])
var _if=
 IF(
    MAX('Table'[Revised Due Date]) =  BLANK(),
    DATEDIFF(
        MAX('Table'[Date]),_select,DAY),
    DATEDIFF(
       MAX('Table'[Revised Due Date]),_select,DAY))
return
DIVIDE(ABS(_if) ,30)

2. Result:

vyangliumsft_0-1720601557141.png

 

Best Regards,

Liu Yang

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

View solution in original post

5 REPLIES 5
v-yangliu-msft
Community Support
Community Support

Hi  @Herchris7172 ,

 

Here are the steps you can follow:

1. Create measure.

Measure =
var _select=SELECTEDVALUE('Calender'[Date])
var _if=
 IF(
    MAX('Table'[Revised Due Date]) =  BLANK(),
    DATEDIFF(
        MAX('Table'[Date]),_select,DAY),
    DATEDIFF(
       MAX('Table'[Revised Due Date]),_select,DAY))
return
DIVIDE(ABS(_if) ,30)

2. Result:

vyangliumsft_0-1720601557141.png

 

Best Regards,

Liu Yang

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

Another way I found out is this 

_months_2 =
Var Due_Date = SELECTEDVALUE(Sheet1[Dates ])
Var Revise_Date = SELECTEDVALUE(Sheet1[Revised Due Date])
Var Results = IF(ISBLANK(Revise_Date), DATEDIFF(Sheet1[Selected-Date],Due_Date,MONTH),DATEDIFF(Sheet1[Selected-Date],Revise_Date,MONTH))
RETURN Results
v-yangliu-msft
Community Support
Community Support

Thanks for the reply from @lbendlin , please allow me to provide another insight: 

Hi  @Herchris7172 ,

 

Here are the steps you can follow:

1. Create measure.

Test =
var _select=SELECTEDVALUE('Calender'[Date])
var _table=
ADDCOLUMNS(
    ALL('Table'),"Datediff",
 IF(
    'Table'[Revised Due Date] =  BLANK(),
    DATEDIFF(
        'Table'[includes Dates],_select,MONTH),
    DATEDIFF(
       'Table'[Revised Due Date],_select,MONTH)))  
return
SUMX(
_table,[Datediff])

2. Result:

 

vyangliumsft_0-1720158598855.png

 

Best Regards,

Liu Yang

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

Thanks for the Reply but am Expecting results like the below. This is in Excel

Herchris7172_0-1720176143240.png

 

lbendlin
Super User
Super User

Read about how to use COALESCE to test for BLANK() and replace it with other values like "TODAY()".

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors