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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Calculate days between dates that cross months

Hi, 

I'm at an impass, I've got a table with the start and end date and a column that identifes the number of dates in between.

 

aguest1005_0-1650970091490.png

 

I've written the following measure

Absence Days in Mth =

VAR firstDayOfMonth =

    MIN ( 'DateDimension'[Date] )

VAR lastDayOfMonth =

    MAX ( 'DateDimension'[Date]  )

RETURN

    SUMX (

        Absence,

        VAR s =

            MAX ( Absence[StartDate], firstDayOfMonth )

        VAR e =

            MIN (Absence[EndDate], lastDayOfMonth )

        RETURN

            IF ( s < e, DATEDIFF ( s-1, e, DAY ) )

    )

 

When I put this measure as a card on my report and then use the Month (date Table) as a filter I get the correct value for March of 4. For April I get 30 rather than 30 + 22 from the first row.

 

My date table is joined to the absence table on date - startdate.

 

How do I get this so it picks up the April figure of the first record when I filter for April.


TIA

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

In general, calendar table in such inteval calculations doesn't function as a dimension like other date-oriented analysis.

 

Tricky solution to the tricky question,

CNENFRNL_0-1650982922647.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

In general, calendar table in such inteval calculations doesn't function as a dimension like other date-oriented analysis.

 

Tricky solution to the tricky question,

CNENFRNL_0-1650982922647.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Anonymous
Not applicable

Thank you, thats worked perfectly.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors