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 September 15. Request your voucher.

Reply
SebaSpotti
Advocate II
Advocate II

Count events beetwen tow dates grouped by a column

Hi all!

 

I have a database of events like this:

PlaceEventIDEvent StartEvent End
STREET101/08/2024 00:00:0002/08/2024 00:00:00
STREET210/08/2024 00:00:0013/08/2024 00:00:00
ROAD301/08/2024 00:00:0015/08/2024 00:00:00
HIGHWAY427/08/2024 00:00:0030/08/2024 00:00:00
STREET501/08/2024 00:00:0030/08/2024 00:00:00
HIGHWAY510/08/2024 00:00:0027/08/2024 00:00:00

 

and a table of the dates of months.

I want to calculate how many events are "opened" per each day of the calendar and also have the possibility to filter them per "Place".

 

I tryed to create a table like this:

DateTableShips = UNION(
ADDCOLUMNS (
    CALENDAR (DATE(2024, 9, 1), DATE(2024, 9, 30)),
    "Year", YEAR([Date]),
    "Month", MONTH([Date]),
    "Place", "STREET"),
ADDCOLUMNS (
    CALENDAR (DATE(2024, 9, 1), DATE(2024, 9, 30)),
    "Year", YEAR([Date]),
    "Month", MONTH([Date]),
    "Place", "ROAD")
)

 

and it works, but if i want to calculate an average per day, for example, the results its obviously lower then what i want with a simple average. 

 

Any suggestions?

1 ACCEPTED SOLUTION

Thanks, with a little correction it works, the code fore Open Events should be this:

 

 

Open Events = 
SUMX (
    'Table',
    IF (
        'Table'[Event Start] <= MIN('Calendar'[Date]) &&
        'Table'[Event End] >= MAX('Calendar'[Date]),
        1,
        BLANK()
    )
)

 

View solution in original post

2 REPLIES 2
DataNinja777
Super User
Super User

Hi @SebaSpotti ,

 

You can achieve the desired output by calculating the duration of open events using a disconnected calendar table and writing the measures as shown below.

Open Events = 
SUMX (
    'Table',
    IF (
        'Table'[Event Start] <= MAX('Calendar'[Date]) &&
        'Table'[Event End] >= MAX('Calendar'[Date]),
        1,
        BLANK()
    )
)
Average open events = averagex('Calendar',[Open events])

 

DataNinja777_0-1727276639579.png

 

I have attached an example pbix file.  Please let me know if this meets your requirements.

Best regards,

Thanks, with a little correction it works, the code fore Open Events should be this:

 

 

Open Events = 
SUMX (
    'Table',
    IF (
        'Table'[Event Start] <= MIN('Calendar'[Date]) &&
        'Table'[Event End] >= MAX('Calendar'[Date]),
        1,
        BLANK()
    )
)

 

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 Kudoed Authors