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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

difference between two dates in weeks

Hi Guys

 

I need your help. 

 

I have data table with order nr and then 4 dates.

- Creation date (this is in date format, but also week and year), 

- Req. week (only in week and year format)

- Last Conf. week (only in week and year format)

- First Conf. week (only in week and year format)

 

I need to calculate the difference between lets say creation week and req. week 

* for example  creation week is 25  and req. week is 48 the difference will be 48-25 =23

This works easy because the difference is a positive but if 

creation week is 45 and the req. week is 5 then 5-45 = -40 which is not true because if year has 52 weeks then the difference should be 52-40 = 12 + 5 = 17 

 

Can someone help me with this calculation. 

 

I would prefer to have it as a column created in dax but M or Measure is also fine. 

 

Thank you 

 

 

Order #Creation DayCreation WeekCreation YearFirst Conf. WeekFirst Conf. YearLast Conf. WeekLast Conf. YearReq. Del. WeekReq. Del.  Year
764027413.02.201872018312018312018312018
800140615.07.2018282018620196201962019
759151627.01.201842018322018322018322018
801636020.07.2018292018620196201962019
751450823.12.2017512017232018232018232018
754996810.01.201822018222018222018222018
770463507.03.2018102018362018362018362018
775855429.03.2018132018362018362018362018
774278722.03.2018122018362018362018362018
773046717.03.2018112018362018362018362018
769280002.03.201892018362018362018362018
766668522.02.201882018362018362018362018
759743330.01.201852018362018362018362018
762623609.02.201862018322018322018322018
776425602.04.2018142018382018372018372018
763572216.05.2018202018382018362018312018
752330427.12.2017522017282018362018282018
791220005.06.2018232018502018452018452018
729989319.09.2017382017152018152018152018
722925028.08.2017352017222018192018102018
715133503.08.20173120171120188201852018
713882228.07.2017302017920189201892018
755212919.01.201832018182018182018182018
663345417.12.2016502016272017262017262017
646927707.10.201640201612201718201772017
634732817.08.2016332016122017122017122017
694807610.05.2017192017442017442017442017
641360609.09.201636201613201714201782017
642925716.09.2016372016202017202017202017
633521912.08.2016322016112017112017112017
541882521.08.2015342015620166201662016
621908101.07.2016262016522016522016522016
580072629.12.2015532015262016262016262016
608149020.04.2016162016362016292016292016
605906512.04.2016152016442016442016442016
567043030.10.2015442015132016132016132016
558159422.09.2015392015242016242016242016
551185505.10.2015412015142016142016142016
550754316.10.2015422015222016202016122016
527180530.06.2015272015420164201642016
705021725.06.2017252017320183201822018
602028102.06.2016222016412016412016412016
1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Greg_Deckler

 

Almost correct

 

this is the correct formula that works 

 

Column =
VAR __dec31 = DATE([Req. Del. Year],12,31)
VAR __weeks = [Req. Del. Week]-[Creation Week]
RETURN
IF(
[Creation Week] > [Req. Del. Week],
WEEKNUM(__dec31) -[Creation Week]+ [Req. Del. Week],
__weeks
)

 

but thank you very much without you I would not able to finish it.. 

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

Perhaps:

 

Column = 
VAR __weeks = [Creation Week] - [Req. Del. Week]
RETURN  
  IF(
    [Req. Del. Week] > [Creation Week],
    52 + __weeks + [Creation Week],
    __weeks
  ) 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

ok thats a good start but how to deal with the fact that each year has a different number of weeks.. 

 

Try this:

 

Column = 
VAR __dec31 = DATE([Req. Del. Year],12,31) VAR __weeks = [Creation Week] - [Req. Del. Week] RETURN IF( [Req. Del. Week] > [Creation Week], WEEKNUM(__dec31) + __weeks + [Creation Week], __weeks )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler

 

Almost correct

 

this is the correct formula that works 

 

Column =
VAR __dec31 = DATE([Req. Del. Year],12,31)
VAR __weeks = [Req. Del. Week]-[Creation Week]
RETURN
IF(
[Creation Week] > [Req. Del. Week],
WEEKNUM(__dec31) -[Creation Week]+ [Req. Del. Week],
__weeks
)

 

but thank you very much without you I would not able to finish it.. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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