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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculating Difference Between Two Dates using Multiple If statements

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

8 REPLIES 8
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

Do you mean to calculate the difference with Duration.Days()? It should be "Duration.Days[PKG.1_DATE2]-[PKG.1_DATE1] )/7"

3-1.PNG

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Anonymous
Not applicable

@v-eachen-msft See message 5. I'm already using the Duration Days in my power query. I need to calculate the Duration Days from the latest package date.

mahoneypat
Microsoft Employee
Microsoft Employee

Is the second custom column referencing the first one?  Maybe just a typo in the post, but the names are different (Latest Package Date vs. Latest Package Delay).

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

@mahoneypat 

No, it should be Latest Package Date. This is not a problem. I need to find the difference in weeks from the latest package date.

Anonymous
Not applicable

if this

 

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]})

 

works, I suspect the column type [PKG.....] is not date.

 

Then the error that probably raises the following expression.

 

Could you give some example of the input table and the expected ouput table?

 

 

 

 

 

 

 

Anonymous
Not applicable

@Anonymous Thanks again for your help.

 

The expected output table for column "Schedule Delay" should be a value for the number of weeks delayed.  

Input Table

mpatzic_0-1594143900321.png

 

Anonymous
Not applicable

and the input table is ...

 

you should give only some fictitious examples of the data you manage.

 

Is important know the number, the order  and the name on the columns involved; the tipical case you wanto to treat:

 

For example if you have the max you are looking for in two differente pkg, which pkg we should considere to calculate the delay.

 

etc etc..

 

 

Anonymous
Not applicable

@Anonymous 

 

Input Table

 

input table.PNG

 

 

Schedule Delay.PNGLatest Package Date.PNGError.PNG

 

 

Date 2 for each package is a revised date. I want to pick the latest revised date and calculate the date difference (in weeks) between the revised date (date 2) and the initial planned date (date 1). 

 

For example, in the input above the difference in PKG.1_Date2 and PKG.1_Date1 is 2. However, since PKG.2_Date2 is the furthest date out, I want to choose that as my baseline and calculate the date difference (in weeks) between the PKG.2_Date2 and PKG.2_Date1. Since there is nothing for PKG.3_Date1 and PKG.3_Date2 in this case, it will not impact the result. However, if there was a date for it, then it may impact the result.

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.