cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper I
Helper I

Calculate number of weeks, if date blank automatically calculate from a different date

Calculate number of wees between 2 dates. If a date is blank use 1/1/2017

 [ New ] 
 
 

Hello all,

 

I need help calculating the number of weeks between 2 columns.  The challenge is one of the columns may be blank at times.  If they are blank i'd like to the formula to use another date automatically.  For the purposes pf this example I have the following columns:

 

Start Date  End Date  # of weeks (need help calculating)
1/1/20175/5/2017 
2/2/20175/5/2017 
6/20/20175/5/2017 
4/15/20175/5/2017 
 5/5/2017 
1/1/2017  5/5/2017 
   
1/1/20175/5/2017 
1/1/2017  
 5/5/2017 
   

 

 

- If the start date is missing, I'd like to use the beginning of the year (1/1/2017) as the start date to calculate the number of weeks.

- If the end date is missing, I'd like to use the current date (today) for the end date.  

- If both dates are present, I'd like to use those dates as is.  

- I will be summing the number of weeks to across different regions and groups to show the total number of weeks active.

 

 

I'm not sure if this is a measurement or if I need to add a column.  I'll be using this rolled up at different levels of  a hierarchy and need to calculations to adjust based on the what the user is filtering by.

 

Any help on this is greatly appreciated.  

ScORE

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User III
Super User III

Re: Calculate number of weeks, if date blank automatically calculate from a different date

Hi @ScORE

 

Try this calculated column

# of weeks =
VAR alternateStartDate =
    DATE ( 2017, 1, 1 )
VAR alternateEndDate =
    TODAY ()
RETURN
    DATEDIFF (
        IF ( ISBLANK ( Table1[Start Date] ), alternateStartDate, Table1[Start Date] ),
        IF ( ISBLANK ( Table1[End Date] ), alternateEndDate, Table1[End Date] ),
        WEEK
    )
Try my new Power BI game Cross the River

View solution in original post

5 REPLIES 5
Highlighted
Solution Sage
Solution Sage

Re: Calculate number of weeks, if date blank automatically calculate from a different date

Probably a few ways to do this - one would be to alter the data in Power Query, so that you fill in the blanks with your desired alternative outcomes, the other would be to create a couple of measures so that you have something like:

 

FixedStartDate = if([StartDate]=null, 01/01/2017, [StartDate])

FixedEndDate = if([EndDate]=null, TODAY(), [EndDate])

 

Syntax might not be exactly right, but it should give you a starting point - you can then take one away from the other and then multiply by 1/7 to get the number of weeks

Highlighted
Super User III
Super User III

Re: Calculate number of weeks, if date blank automatically calculate from a different date

Hi @ScORE

 

Try this calculated column

# of weeks =
VAR alternateStartDate =
    DATE ( 2017, 1, 1 )
VAR alternateEndDate =
    TODAY ()
RETURN
    DATEDIFF (
        IF ( ISBLANK ( Table1[Start Date] ), alternateStartDate, Table1[Start Date] ),
        IF ( ISBLANK ( Table1[End Date] ), alternateEndDate, Table1[End Date] ),
        WEEK
    )
Try my new Power BI game Cross the River

View solution in original post

Highlighted
Super User III
Super User III

Re: Calculate number of weeks, if date blank automatically calculate from a different date

@ScORE

 

1005.png

Try my new Power BI game Cross the River
Highlighted
Microsoft
Microsoft

Re: Calculate number of weeks, if date blank automatically calculate from a different date

Hi @ScORE,

 

Have you tried the solutions provided above? Do they work in your scenario? If some solution works, could you accept it as solution to close this thread?

 

If you still have any question on this issue, feel free to post here. Smiley Happy

 

Regards

Highlighted
Helper I
Helper I

Re: Calculate number of weeks, if date blank automatically calculate from a different date

Thank you!  This worked and is giving me what I need.  The only problem isthe tables are ommitting instances where there should be data; not pulling everything in.  

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors