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

Measure help needed - Count values for each period

Hello, 

Can anyone help me please to create measure with following scenario?

I have table:

NameDate startDate end
ABC05.07.202028.09.2020
CDE15.08.202028.08.2020

What i need is to count "Name" in each period between date start and date end. And then crate chart with data distributed like 

in table below:

YearMonthQty
2020July1
2020August2
2020September1

 

Total for Year 2020 should be equal to 2. 

 

Will appreciate any help. 

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

 

 

// T is your table with
// Name|DateStart|DateEnd
// You also should have a Dates
// table in the model that
// is the calendar date. Dates
// should NOT be connected to
// T in any way. Then you can write:

[Qty] =
var __minDate = min( Dates[Date] )
var __maxDate = max( Dates[Date] )
var __output =
    // This works on condition that
    // the T table stores different
    // Names on each row. If this is
    // not the case, then you have to
    // use the (2) formula.
    COUNTROWS(
        filter(
            T,
            var __dateStart = T[DateStart]
            var __dateEnd = T[DateEnd]
            return
            NOT ISEMPTY(
                filter(
                    Dates,
                    __dateStart <= Dates[Date]
                    &&
                    Dates[Date] <= __dateEnd
                )
            )
        )
    )
/* (2)
var __output =
    CALCULATE(
        DISTINCTCOUNT( T[Name] ),
        filter(
            T,
            var __dateStart = T[DateStart]
            var __dateEnd = T[DateEnd]
            return
            NOT ISEMPTY(
                filter(
                    Dates,
                    __dateStart <= Dates[Date]
                    &&
                    Dates[Date] <= __dateEnd
                )
            )
        )        
    )
*/
return
    __output

 

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

 

 

// T is your table with
// Name|DateStart|DateEnd
// You also should have a Dates
// table in the model that
// is the calendar date. Dates
// should NOT be connected to
// T in any way. Then you can write:

[Qty] =
var __minDate = min( Dates[Date] )
var __maxDate = max( Dates[Date] )
var __output =
    // This works on condition that
    // the T table stores different
    // Names on each row. If this is
    // not the case, then you have to
    // use the (2) formula.
    COUNTROWS(
        filter(
            T,
            var __dateStart = T[DateStart]
            var __dateEnd = T[DateEnd]
            return
            NOT ISEMPTY(
                filter(
                    Dates,
                    __dateStart <= Dates[Date]
                    &&
                    Dates[Date] <= __dateEnd
                )
            )
        )
    )
/* (2)
var __output =
    CALCULATE(
        DISTINCTCOUNT( T[Name] ),
        filter(
            T,
            var __dateStart = T[DateStart]
            var __dateEnd = T[DateEnd]
            return
            NOT ISEMPTY(
                filter(
                    Dates,
                    __dateStart <= Dates[Date]
                    &&
                    Dates[Date] <= __dateEnd
                )
            )
        )        
    )
*/
return
    __output

 

 

Anonymous
Not applicable

Worked perfectly! Thanks!

Anonymous
Not applicable

Wow, thanks, i will test is now and post results soon!

 

Thank you!

 

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.