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
usman96
Helper II
Helper II

difference between dates

How To Count The Days Excluding Sundays Between Two Dates  ? 

1 ACCEPTED SOLUTION

@usman96

 

Please see the attached file

 

usman.png


Regards
Zubair

Please try my custom visuals

View solution in original post

17 REPLIES 17
Tertxu
Regular Visitor

Hey, Im struggling calculating average of a column which contains difference between two dates. When calculating in excel the results is ok, but not in power bi. 

Steps I´ve followed (as an exacmple):

1; If (B1=blank():blank():(B1-A1))

2. New measure: average column

 

Any suggestion?

Hi,

 

  1. Is your IF formual a calculated column or a measure?
  2. What measure have you written for computing the average?
  3. What result are you getting with that measure?
  4. What result are ou expecting?
  5. What does your data look like?

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hey, 

 

Let me explain myself a little better. In excel I have the following:

 

Date Created    Date Assigned    Date Finished

 

Some of them are blank. I want to have three measures: 

1, Days between Date created and date finished. After that, I want to calculate the average excluding blanks

2. Days between date created and date assigned. After that, I want to calculate the average excluding blanks

3. Days between date assigned and date finished. After that, I want to calculate the average excluing blanks. 

 

The "new column" im including in power bi is just as simple as: if(date assigned=blank();blank();(date assigned-date created)

 

The "new measure" = average(new column)

 

The results in excel are accurate (average aprox 1.2) and in power bi are over 30 days, which doesnt make sense... 

 

Any ideas? Its driving my crazy 😞

That's strange.  Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Zubair_Muhammad
Community Champion
Community Champion

Hi @usman96

 

You can use this calculated column....assuming you have Startdate and Enddate columns

 

Count Business Days =
VAR MyDates =
    ADDCOLUMNS (
        GENERATESERIES ( TableName[StartDate] + 1, TableName[ EndDate] ),
        "Day", WEEKDAY ( [Value], 2 )
    )
RETURN
    COUNTROWS ( FILTER ( mydates, [Day] <= 6 ) )

Regards
Zubair

Please try my custom visuals

what is "value" in your formula

@usman96

 

It is the temporary Column created by the temporary table

GENERATESERIES ( TableName[StartDate] + 1, TableName[ EndDate] ),



for each row of your table

 

 


Regards
Zubair

Please try my custom visuals

@usman96

 

Please see the attached file here


Regards
Zubair

Please try my custom visuals

I only have date column  , not starting  date and ending date

 

 

@usman96

 

Then what difference do you want to count if you have a single date?

 

You can copy paste some sample data here with expected results

 

For example

 

StartDate EndDateCount Business Days
Monday, January 1, 2018Saturday, January 13, 201811
Tuesday, January 9, 2018Thursday, January 18, 20188
Thursday, January 18, 2018Wednesday, January 31, 201811

Regards
Zubair

Please try my custom visuals

samples.PNG

I have a single column like this and  i want to find how many days between these two dates (exlcuding sunday) 

(as u can see , one is smaller date and one is larger )

@usman96

 

Do you have only 2 dates in your Column?


Regards
Zubair

Please try my custom visuals

yes for now  , but as enter more data .............. the table structure should be like  in Ascending order  (Smaller dates to larger dates)

@usman96

 

Suppose you have a table like this

 

Date
Monday, January 1, 2018
Saturday, January 13, 2018
Sunday, January 21, 2018
Saturday, February 3, 2018

 

You can add a calculated column to get the difference from next date using this formula

 

Difference from Next date =
VAR NextDate =
    CALCULATE (
        MIN ( Table1[Date] ),
        FILTER ( ALL ( Table1 ), Table1[Date] > EARLIER ( Table1[Date] ) )
    )
VAR Next_date =
    IF ( ISBLANK ( NextDate ), Table1[Date] + 1, NextDate )
VAR MyDates =
    ADDCOLUMNS (
        GENERATESERIES ( Table1[Date] + 1, Next_Date ),
        "Day", WEEKDAY ( [Value], 2 )
    )
RETURN
    COUNTROWS ( FILTER ( mydates, [Day] <= 6 ) )

Regards
Zubair

Please try my custom visuals

@usman96

 

Please see the attached file

 

usman.png


Regards
Zubair

Please try my custom visuals

Thanks 🙂 

what should i do ?

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.