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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
PBI_newuser
Post Prodigy
Post Prodigy

How to calculate the days difference between calendar date and created date

Hi, I have below data (Table 1) and I want to count the job which open more than 100 days based on the calendar month.

Example:

For Job# = J-111, in Oct 2021, the days diff between the last day of Oct 2021 (10/31/2021) and the Created Date is 102 days.

For J-777, there is a closed date. In Sep 2021, the job is not closed and the days difference should be calculated from 03/06/2021 to 9/30/2021 which is 208 days. In Oct 2021, J-777 is closed and the days difference should be calculated from 03/06/2021 to 10/18/2021 which is 226 days.

 

Then I want to create a chart to count number of jobs in each month which is more than 100 days.

I do not know how to create the measurse of the days difference.  Here is the pbix file.

 

Table 1:

Job#Created DateClosed Date... Aug 2021Days Diff in Sep 2021Days Diff in Oct 2021Days Diff in Nov 2021...
J-11107/21/2021  71102132 
J-12308/09/2021  5283113 
J-13209/02/2021  285989 
J-22206/25/2021  97128158 
J-44405/06/2021  147178208 
J-55511/01/2021  -32-129 
J-66610/10/2021  -102151 
J-77703/06/202110/18/2021 208226226 
J-88802/08/2021  234265295 
J-99901/11/20219/11/2021 243243243 

 

PBI_newuser_1-1639991573572.png

 

1 ACCEPTED SOLUTION

Hi @PBI_newuser ,

According to your description, I modify my formula like this.

Job Count =
VAR _DIFF =
    IF (
        ISBLANK ( MAX ( 'Table'[Closed Date] ) ),
        DATEDIFF (
            MAX ( 'Table'[Created Date] ),
            MAXX (
                FILTER (
                    ALL ( 'Calendar' ),
                    'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
                ),
                'Calendar'[Date]
            ),
            DAY
        ),
        DATEDIFF (
            MAX ( 'Table'[Created Date] ),
            MIN (
                MAX ( 'Table'[Closed Date] ),
                MAXX (
                    FILTER (
                        ALL ( 'Calendar' ),
                        'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
                    ),
                    'Calendar'[Date]
                )
            ),
            DAY
        )
    )
RETURN
    IF (
        ISBLANK ( MAX ( 'Table'[Closed Date] ) ),
        IF (
            MAXX (
                FILTER (
                    ALL ( 'Calendar' ),
                    'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
                ),
                'Calendar'[Date]
            )
                < MAX ( 'Table'[Created Date] ),
            BLANK (),
            _DIFF
        ),
        IF (
            MAXX (
                FILTER (
                    ALL ( 'Calendar' ),
                    'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
                ),
                'Calendar'[Date]
            )
                < MAX ( 'Table'[Created Date] )
                || MINX (
                    FILTER (
                        ALL ( 'Calendar' ),
                        'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
                    ),
                    'Calendar'[Date]
                )
                    > MAX ( 'Table'[Closed Date] ),
            BLANK (),
            _DIFF
        )
    )

Get the expected result.

vkalyjmsft_0-1640762857576.png

I attach my sample below for reference.

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
v-yanjiang-msft
Community Support
Community Support

Hi @PBI_newuser ,

According to your description, here's my solution.

1.Create a column in calendar table.

 

MonthYear = FORMAT('Calendar'[Date],"YYYY-MM")

 

2.Create a measure, I let the negtive number be blank in my formula.

 

Job Count =
VAR _DIFF =
    DATEDIFF (
        MAX ( 'Table'[Created Date] ),
        COALESCE (
            MAX ( 'Table'[Closed Date] ),
            MAXX (
                FILTER (
                    ALL ( 'Calendar' ),
                    'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
                ),
                'Calendar'[Date]
            )
        ),
        DAY
    )
RETURN
    IF (
        _DIFF < 0
            || MAXX (
                FILTER (
                    ALL ( 'Calendar' ),
                    'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
                ),
                'Calendar'[Date]
            )
                < MAX ( 'Table'[Created Date] ),
        BLANK (),
        _DIFF
    )

 

Put Job in rows, Monthyear in columns and Job count in values.

vkalyjmsft_1-1640339052941.png

I attach my sample below for reference.

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Hi @v-yanjiang-msft , thank you for the solution. How to modify the measure of Job Count to calculate the day difference between last day of the month and created date?

For example, J-777, in the month of 2021-03, the job is not closed, so it should calculate the day difference between 03/06/2021 to 03/31/2021 which is 25 days. 

In 2021-04, it should calculate from 03/06/2021 to 04/30/2021 which is 55 days.

PBI_newuser_0-1640564832792.png

 

Hi @PBI_newuser ,

According to your description, I modify my formula like this.

Job Count =
VAR _DIFF =
    IF (
        ISBLANK ( MAX ( 'Table'[Closed Date] ) ),
        DATEDIFF (
            MAX ( 'Table'[Created Date] ),
            MAXX (
                FILTER (
                    ALL ( 'Calendar' ),
                    'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
                ),
                'Calendar'[Date]
            ),
            DAY
        ),
        DATEDIFF (
            MAX ( 'Table'[Created Date] ),
            MIN (
                MAX ( 'Table'[Closed Date] ),
                MAXX (
                    FILTER (
                        ALL ( 'Calendar' ),
                        'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
                    ),
                    'Calendar'[Date]
                )
            ),
            DAY
        )
    )
RETURN
    IF (
        MAXX (
            FILTER (
                ALL ( 'Calendar' ),
                'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
            ),
            'Calendar'[Date]
        )
            < MAX ( 'Table'[Created Date] ),
        BLANK (),
        _DIFF
    )

Then get the expected result.

vkalyjmsft_0-1640684140153.png

I attach my sample below for reference.

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yanjiang-msft , how to stop calculating the day difference after the closed date?

This is because I am calculating how many jobs are not closed in each month. Once it's closed, it shouldn't be counted. For example, day difference in 2021-11 for J-777 should be blank.

 

Job = CALCULATE(COUNTX('Table',[Job Count]),FILTER('Table',[Job Count]>100))

PBI_newuser_0-1640761737831.png

 

Hi @PBI_newuser ,

According to your description, I modify my formula like this.

Job Count =
VAR _DIFF =
    IF (
        ISBLANK ( MAX ( 'Table'[Closed Date] ) ),
        DATEDIFF (
            MAX ( 'Table'[Created Date] ),
            MAXX (
                FILTER (
                    ALL ( 'Calendar' ),
                    'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
                ),
                'Calendar'[Date]
            ),
            DAY
        ),
        DATEDIFF (
            MAX ( 'Table'[Created Date] ),
            MIN (
                MAX ( 'Table'[Closed Date] ),
                MAXX (
                    FILTER (
                        ALL ( 'Calendar' ),
                        'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
                    ),
                    'Calendar'[Date]
                )
            ),
            DAY
        )
    )
RETURN
    IF (
        ISBLANK ( MAX ( 'Table'[Closed Date] ) ),
        IF (
            MAXX (
                FILTER (
                    ALL ( 'Calendar' ),
                    'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
                ),
                'Calendar'[Date]
            )
                < MAX ( 'Table'[Created Date] ),
            BLANK (),
            _DIFF
        ),
        IF (
            MAXX (
                FILTER (
                    ALL ( 'Calendar' ),
                    'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
                ),
                'Calendar'[Date]
            )
                < MAX ( 'Table'[Created Date] )
                || MINX (
                    FILTER (
                        ALL ( 'Calendar' ),
                        'Calendar'[MonthYear] = MAX ( 'Calendar'[MonthYear] )
                    ),
                    'Calendar'[Date]
                )
                    > MAX ( 'Table'[Closed Date] ),
            BLANK (),
            _DIFF
        )
    )

Get the expected result.

vkalyjmsft_0-1640762857576.png

I attach my sample below for reference.

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yanjiang-msft , that's what I am expecting! Thank you so much!! 😉

amitchandak
Super User
Super User

@PBI_newuser , assuming this date is coming from a slicer or from a date table

 

try a measure like

Sumx(Table, Datediff([Created Date], coalesce([close date], max('Date'[Date])),Day))

or

Sumx(values(Table[JOB#], Datediff(Min(Table[Created Date]), coalesce(Max(Table([close date]), max('Date'[Date])),Day))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak , it doesn't work. Here is the pbix file.

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.

Top Solution Authors