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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Number of days

Hi,

I have 2 sets of dates in my dataset, event start date and event end date. I need to create a visual which shows the number of days in a month the event has been active. For example if the start date is 10/12/2021 and end date is 11/2/2022 for a particular event, then in a month by month visual it should show as 

year   month   number of days

2021   12             21

2022    1              31

2022    2              11

 

Appreciate anyhelp.

Thanks

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I am not sure how your data model looks like, but I tried to create a sample pbix file like below.

Picture1.png

 

 

 

Number of Days: =
CALCULATE (
    COUNTROWS ( 'Calendar' ),
    FILTER (
        'Calendar',
        'Calendar'[Date] >= MAX ( Events[StartDate] )
            && 'Calendar'[Date] <= MAX ( Events[EndDate] )
    )
)

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I am not sure how your data model looks like, but I tried to create a sample pbix file like below.

Picture1.png

 

 

 

Number of Days: =
CALCULATE (
    COUNTROWS ( 'Calendar' ),
    FILTER (
        'Calendar',
        'Calendar'[Date] >= MAX ( Events[StartDate] )
            && 'Calendar'[Date] <= MAX ( Events[EndDate] )
    )
)

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Hi Jihwan,

Below is what I got from the solution you provided.

spill003_1-1648599831729.png

 

As you can see I have these measures running in 2 different tables. Now I need to compare the results. As you can see one starts from Mar 2020 and other from Jan 2017. How would I limit the second table to show only the results from March 2020, ie filter the Month year from one table to only have values that other one has.

Thanks in Advance

Hi,

Thank you for your feedback.

I am not sure if I understood your question correctly, but please try to include the condition in the measure. I am not sure if the below works for your data model because I do not know your data model, but please try.

 

Number of Days V2: =
IF (
    MIN ( 'Calendar'[Date] ) >= DATE ( 2020, 03, 01 ),
    CALCULATE (
        COUNTROWS ( 'Calendar' ),
        FILTER (
            'Calendar',
            'Calendar'[Date] >= MAX ( Events[StartDate] )
                && 'Calendar'[Date] <= MAX ( Events[EndDate] )
        )
    )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Thanks again, this works well if the dates are continuous. For example lets say I have these set of dates 

spill003_0-1648631472846.png

Here ideally it should work from March 2014 to Sept 2014 and then from 10/07/2021 to 29/08/2021 and then again from 10/02/2022 to present date (1/01/9998 represents future or ongoing)

CALCULATE (
COUNTROWS ( 'Date' ),
FILTER (
'Date',
'Date'[Date] >= MIN ( xyz[_start] )
&& 'Date'[Date] <= MAX ( xyz[_end] )
)
)
cannot do this as it finds the max and min and assumes its continuous. Whats the work around?
Thanks again

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.