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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Data5
New Member

Count Number of Months per Year a project is running given a start date and an end date

Given a field labeled "Start Date" with data of 11/5/2023 and a second field labeled "End Date" with date of 3/15/2025, how do I add columns of 2023 Month Count, 2024 Month Count and 2025 Month Count with expected results of 2, 12 and 3, respectively?  I'm open to either Dax or PowerQuery examples whichever is most efficient would be preferred though.  Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @Data5,

It sound like a common multiple date fields analysis requirement, I'd like to suggest you take a look at the following start/end date part if them suitable for your scenario:
Before You Post, Read This: start, end date  

Regards,

Xiaoxin Sheng

View solution in original post

2 REPLIES 2
Data5
New Member

Thanks for the suggestion.  I ended up using the code below:

2024 Month Count =
IF (
    YEAR ( [Start date] ) = 2024,
    DATEDIFF ( [Start date], DATE ( 2024, 12, 31 ), MONTH )+1,
    IF (
        YEAR ( [Start date] ) = 2024 && YEAR ( [End Date] ) = 2024,
        DATEDIFF ( [Start date], [End Date], MONTH )+1,
        IF (
            YEAR ( [End Date] ) = 2024,
            DATEDIFF ( DATE ( 2024, 12, 31 ), [End Date], MONTH )+12,
            IF (
                AND(YEAR([Start Date]) < 2024, YEAR([End Date]) > 2024),
                12,
                0
            )
        )
    )
)

 

Anonymous
Not applicable

HI @Data5,

It sound like a common multiple date fields analysis requirement, I'd like to suggest you take a look at the following start/end date part if them suitable for your scenario:
Before You Post, Read This: start, end date  

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors