cancel
Showing results for
Did you mean:
Helper V

## Count Difference between dates broken out by month

Is there a way to calculate the difference between two dates but break them out by months?

My table example is:

 ID Date Start Date End Duration 123 12/11/2018 16/11/2018 5 123 02/01/2019 07/01/2019 6 1003 03/06/2019 07/08/2019 66

This count works fine for short dates within the same month but I'm hoping to get a month count between the start and end dates?

So I'm hoping to have some sort of breakout/ split to show:

 ID June July August 1003 28 31 7

Thanks.

1 ACCEPTED SOLUTION
Super User

@Niiru1  firstly, you need create a date table, which have no relationship with your fact table. then try this code

``````DaysCount :=
SUMX (
Table1,
VAR sd = Table1[Date Start]
VAR ed = Table1[Date End]
RETURN
CALCULATE (
COUNT ( 'Calendar'[Date] ),
KEEPFILTERS ( DATESBETWEEN ( 'Calendar'[Date], sd, ed ) )
)
)``````

2 REPLIES 2
Super User

@Niiru1 , refer if this file, I created in the past for similar problem can help

https://www.dropbox.com/s/bqbei7b8qbq5xez/leavebetweendates.pbix?dl=0

Learn Power BI - Full Course with Dec-2022, with new DAX functions like Window, Index, Offset !!
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Formatted Profit and Loss Statement with empty lines
Super User

@Niiru1  firstly, you need create a date table, which have no relationship with your fact table. then try this code

``````DaysCount :=
SUMX (
Table1,
VAR sd = Table1[Date Start]
VAR ed = Table1[Date End]
RETURN
CALCULATE (
COUNT ( 'Calendar'[Date] ),
KEEPFILTERS ( DATESBETWEEN ( 'Calendar'[Date], sd, ed ) )
)
)``````

Announcements

#### 2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

#### Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

#### 2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.

Top Solution Authors
Top Kudoed Authors