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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Anonymous
Not applicable

Calculating difference between two dates in weeks in an if statement

DATE1 =1/1/2020

DATE2 = 1/14/2020 

 

Conditional Columns Created

 PKG.1 = Table.AddColumn(#"Removed Columns", "PKG.1", each if [DATE2] = null then false else if [DATE1] = null then false else true)

 

Custom Column created but did not work. The result = 0.

 Delay in Weeks = ( if[PKG.1] = "True" then Duration.Days(Duration.From[DATE2]-[DATE1]) / 7 else 0)

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

you could get the difference directly wothout thw intwrmwdiate add-column in this way and then raplace null with 0.

 

image.png

 

 

but if you want continue your way, try this change:

 

image.png

 

image.png

 

pay attention to the condition if [goodate] then  also if [goodate]=true then would have been fine.

but if [goodate]="true" doesn't check what you intend i.e. the logical value true . This expression check instead the text "true" which is different value of true.

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

you could get the difference directly wothout thw intwrmwdiate add-column in this way and then raplace null with 0.

 

image.png

 

 

but if you want continue your way, try this change:

 

image.png

 

image.png

 

pay attention to the condition if [goodate] then  also if [goodate]=true then would have been fine.

but if [goodate]="true" doesn't check what you intend i.e. the logical value true . This expression check instead the text "true" which is different value of true.

 

Anonymous
Not applicable

Thank you! the 2nd option worked for me. I have another multiple "if statement" that I'm having issues with. 

 

PKG.1_DATE1 =1/1/2020

PKG.1_DATE2 = 1/14/2020 

PKG.2_DATE1 = 1/2/2020

PKG.2_DATE2 = 1/20/2020 

 

This worked

Custom Column -> Latest Package Delay = if List.Max({[PKG.1_DATE2], [PKG.2_DATE2]}) = 0 then null else List.Max({[PKG.1_DATE2], [PKG.2_DATE2]})

 

This does not work

 

Custom Column -> Schedule Delay = if [Latest Package Date] = null then 0 else if [Latest Package Date] = [PKG.1_DATE2] then (Duration.Days [PKG.1_DATE2]-[PKG.1_DATE1])/7 else if [Latest Package Date] = [PKG.2_DATE2] then (Duration.Days [PKG.2_DATE2]-[PKG.2_DATE1])/7 else 0

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.