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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
NG1407
Frequent Visitor

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
Frequent Visitor

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.