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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
NG1407
Helper I
Helper I

Count ID that has startdate on or before 10th of each month and enddate is after 10th of that month

I need to find the count of only those ID that has startdate <= 10 and enddate > 10 for each month . In other words need to find count of ID that are active till current selected month. A record is active if its enddate is greater than 10th of that month.

For example for jan month I need to count all those ID that has startdate less than or equal to 10thjan and startdate should contain dates from previous month as well that has end date > 10thjan or in future).

 below is the sample data : 

StartdateenddateID
2024-01-102024-12-01a123
2023-12-112024-01-11b123
2024-01-022024-11-08c123
2024-02-112024-02-28d123
2024-03-032024-03-10e123
2024-03-032024-03-15f123

According to above data for jan month the count should be 3, for feb month count should be 0,for march its 1.

I need to display data in line graph. The issue is its filtering the data and showing only jan month data not december month.

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You can use

Num active =
VAR CurrentMonth =
    MAX ( 'Date'[Date] )
VAR CutOffDate =
    DATE ( YEAR ( CurrentMonth ), MONTH ( CurrentMonth ), 10 )
VAR Result =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[ID] ),
        'Table'[Start date] <= CutOffDate,
        'Table'[End date] > CutOffDate
            || ISBLANK ( 'Table'[End date] ),
        REMOVEFILTERS ( 'Date' )
    )
RETURN
    Result

If you know that there is only 1 row per ID then you could use COUNTROWS('Table') instead of DISTINCTCOUNT which might be faster.

View solution in original post

2 REPLIES 2
NG1407
Helper I
Helper I

Thank you 🙂 @johnt75 

johnt75
Super User
Super User

You can use

Num active =
VAR CurrentMonth =
    MAX ( 'Date'[Date] )
VAR CutOffDate =
    DATE ( YEAR ( CurrentMonth ), MONTH ( CurrentMonth ), 10 )
VAR Result =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[ID] ),
        'Table'[Start date] <= CutOffDate,
        'Table'[End date] > CutOffDate
            || ISBLANK ( 'Table'[End date] ),
        REMOVEFILTERS ( 'Date' )
    )
RETURN
    Result

If you know that there is only 1 row per ID then you could use COUNTROWS('Table') instead of DISTINCTCOUNT which might be faster.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.