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
Anonymous
Not applicable

Calculation for number of days per month within different periods of time

Hi.

 

I have been trying without success to calculate the number of days within a given period of time that streches between different months. I need to display in a visual the number of days X month. 

 

The dataset I have is something like this:

1.JPG

As you can see, some periods begin in one month and end in the following.

 

The result I am looking for is as below, where the number of days used is placed in the respective month it belongs to:

2.JPG


Any help is appreciated! I am stuck with this issue for days...

Thanks!! 

1 ACCEPTED SOLUTION
Portrek
Resolver III
Resolver III

Hi lltat.

Look this video below, maybe helps you.

https://www.youtube.com/watch?v=R8tDKwimSsY

 

Best regards.

View solution in original post

4 REPLIES 4
richbenmintz
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

As mentioned in the Video suggested, you can use a dsiconnected date table to generate the values you are looking for along with the following Measure

 

Days of Use = 
var _monthstart = MIN('Calendar'[Date])
var _monthend = MAX('Calendar'[Date])
return
SUMX('Table', 
    SWITCH(TRUE(),
        'Table'[Start Time] < _monthstart && 'Table'[End Time] < _monthstart  , BLANK(), // Blank for empty intersections
        'Table'[End Time] < _monthend && 'Table'[Start Time] >= _monthstart, DATEDIFF('Table'[Start Time], 'Table'[End Time], DAY), 
        'Table'[Start Time] >= _monthstart && 'Table'[End Time] >= _monthend && DATEDIFF('Table'[Start Time], _monthend, DAY) > 0, DATEDIFF('Table'[Start Time], _monthend, DAY),
        'Table'[Start Time] < _monthstart && 'Table'[End Time] <= _monthend, DATEDIFF(_monthstart, 'Table'[End Time], DAY)+1,
        BLANK())
)

 

Results in the following Matrices

richbenmintz_0-1625522902160.png

I am also attaching a sample pbix with a simple calendar table and the measure.

 

I hope this helps.

 



I hope this helps,
Richard

Did I answer your question? Mark my post as a solution! Kudos Appreciated!

Proud to be a Super User!


good...
the truth is that the formula gives me results much closer to those of the video, but I have 2 drawbacks. when the stay for example is an annual stay, it adds the 365 days of the year in the subtotals but in the table or graphs it only shows me the month of beginning and closing.

and on the other hand randomly there are rows that do not count them


PBI muestra.png

Portrek
Resolver III
Resolver III

Hi lltat.

Look this video below, maybe helps you.

https://www.youtube.com/watch?v=R8tDKwimSsY

 

Best regards.

Anonymous
Not applicable

Thanks!! That was exactly what I was looking for! (★‿★)

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