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

View all the Fabric Data Days sessions on demand. View schedule

Reply
mazwro
Helper II
Helper II

Count of occurences outside of date range

I have a table:

- Incident ID

- Date incident was opened

- Date incident was closed

 

I also have a slicer showig months

 

This links to my dim-date table on Dim_date.Date = date incident opened.

 

I want to calculate a number of Incidets which were opened BEFORE the month selected and they must have been closed AFTER the month selected.

 

Please help to point out where I am going wrong:

Opened Prior to Period Not closed = 
VAR SelectedStartDate = MIN(dim_date[Date]) -- Start date from slicer
VAR SelectedEndDate = MAX(dim_date[Date]) -- End date from slicer
RETURN
CALCULATE(
DISTINCTCOUNT(vw_PM_Dashboard[IDINC]),
vw_PM_Dashboard[Created DATE] < SelectedStartDate && vw_PM_Dashboard[Closed DATE] > SelectedEndDate,
REMOVEFILTERS(dim_date[Date]) -- Ignore slicer filters on the date dimension
)
1 ACCEPTED SOLUTION

Don't know much about your data and model. Without representative data hard to give exact solution. You could try troubleshooting your code that

1. The date range selected in the slicer actually includes dates that meet the conditions. If the selected date range does not cover any incidents that were opened before the start date and closed after the end date, the result will be blank.

2. Verify that the date columns (Created DATE and Closed DATE) are of the correct data type (Date). If they are stored as text, the comparison might not work as expected.

Create a temporary measure to check the values of SelectedStartDate and SelectedEndDate:

 

SelectedDatesCheck = 
VAR SelectedStartDate = MIN(dim_date[Date])
VAR SelectedEndDate = MAX(dim_date[Date])
RETURN
"Start Date: " & FORMAT(SelectedStartDate, "YYYY-MM-DD") & " | End Date: " & FORMAT(SelectedEndDate, "YYYY-MM-DD")

 

 

Hope this helps!

View solution in original post

4 REPLIES 4
danextian
Super User
Super User

Hi @mazwro 

 

Try the following:

 

Opened Prior to Period Not closed =
VAR SelectedStartDate =
    MIN ( Dates[Date] ) -- Start date from slicer
VAR SelectedEndDate =
    MAX ( Dates[Date] ) -- End date from slicer
VAR test =
    CALCULATE (
        [Total Revenue],
        FILTER (
            ALL ( Dates ),
            Dates[Date] < SelectedStartDate
                || Dates[Date] > SelectedEndDate
        )
    )
VAR test2 =
    CALCULATE (
        [Total Revenue],
        FILTER ( ALL ( Dates ), Dates[Date] < SelectedStartDate )
    )
        + CALCULATE (
            [Total Revenue],
            FILTER ( ALL ( Dates ), Dates[Date] > SelectedEndDate )
        )
RETURN
    test2

 

 

Both test and test2 variables should return the same value.

danextian_0-1736759729248.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
shafiz_p
Super User
Super User

Hi @mazwro Try this:

 

OpenedPriorToPeriodNotClosed = 
VAR SelectedStartDate = MIN(dim_date[Date]) -- Start date from slicer
VAR SelectedEndDate = MAX(dim_date[Date]) -- End date from slicer
RETURN
CALCULATE(
    DISTINCTCOUNT(vw_PM_Dashboard[IDINC]),
    vw_PM_Dashboard[Created DATE] < SelectedStartDate,
    vw_PM_Dashboard[Closed DATE] > SelectedEndDate,
    REMOVEFILTERS(dim_date[Date]) -- Ignore slicer filters on the date dimension
)

 

 

The main issue with your original code was the way the conditions were combined within the CALCULATE function. The conditions should be separated by commas rather than combined with &&

 

Hope this helps!!

If this solved your problem, please accept it as a solution and a kudos!!

 

Best Regards,
Shahariar Hafiz

Hello @shafiz_p Thanks for your help, unfortunately I already tried this version and it only gives me blank card and I have no clue why:
What could be the reason for this?

mazwro_1-1736753803549.png

 

 

Don't know much about your data and model. Without representative data hard to give exact solution. You could try troubleshooting your code that

1. The date range selected in the slicer actually includes dates that meet the conditions. If the selected date range does not cover any incidents that were opened before the start date and closed after the end date, the result will be blank.

2. Verify that the date columns (Created DATE and Closed DATE) are of the correct data type (Date). If they are stored as text, the comparison might not work as expected.

Create a temporary measure to check the values of SelectedStartDate and SelectedEndDate:

 

SelectedDatesCheck = 
VAR SelectedStartDate = MIN(dim_date[Date])
VAR SelectedEndDate = MAX(dim_date[Date])
RETURN
"Start Date: " & FORMAT(SelectedStartDate, "YYYY-MM-DD") & " | End Date: " & FORMAT(SelectedEndDate, "YYYY-MM-DD")

 

 

Hope this helps!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors