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

Count Distinct Dates Between Start Date and End Date Columns

Suppose I have this: 

 

MemberStartEnd
member11/1/20191/5/2019
member11/1/20191/5/2019
member11/1/20191/6/2019
member23/1/20193/2/2019
member23/1/20193/3/2019

 

This table reflects six distinct dates for member1: 1/1/19, 1/2/19, 1/3/19, 1/4/19, 1/5/19, and 1/6/19. 

..and three distinct dates for member2: 3/1/19, 3/2/19, 3/3/19

 

Is it possible to create a Measure to compute something like this?

The measure would compute the number of distinct dates per member, based on the Start and End date.

 

I've been working on this for hours - any ideas would be appreciated. 

Thanks!

Brian 

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

@bricohen1 

try to create a table

Table Calendar = 
ADDCOLUMNS(
crossjoin(calendar(min('Table'[Start]);max('Table'[End]));distinct('Table'[Member]));
"is in day";if(calculate(count('Table'[Member]);filter('Table'; 'Table'[Start]<=[Date] && 'Table'[End] >= [Date] && EARLIER('Table'[Member])=[Member]))>0;1;0)
)

then just summarize it:

Table Total = summarize('Table Calendar';'Table Calendar'[Member];"Count";SUM('Table Calendar'[is in day]))

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

6 REPLIES 6
Mariusz
Community Champion
Community Champion

Hi @bricohen1 

 

Try something like this.

Measure = 
CALCULATE(
    DATEDIFF(
        MIN( 'Table'[Start] ), 
        MAX( 'Table'[End] ),
        DAY
    ), 
    ALL( 'Table' ),
    VALUES( 'Table'[Member] )
)
Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

az38
Community Champion
Community Champion

Hi @bricohen1 

what exactly result do you expect?

anyway try a measure

Measure = 
DATEDIFF(CALCULATE(MIN('Table'[Start]);ALLEXCEPT('Table';'Table'[Member]));CALCULATE(MAX('Table'[END]);ALLEXCEPT('Table';'Table'[Member]));DAY)

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

@az38 thanks for working on it. Using DATEDIFF is a good idea, but it's not quite right.

 

With the above example,

Member1 = 6.

Member2 = 3.

 

Brian

az38
Community Champion
Community Champion

So, @bricohen1 

Measure = 
DATEDIFF(CALCULATE(MIN('Table'[Start]);ALLEXCEPT('Table';'Table'[Member]));CALCULATE(MAX('Table'[END]);ALLEXCEPT('Table';'Table'[Member]));DAY)+1

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

@az38 @Mariusz 

 

Thanks guys. 

The problem is, the dates may not be consecutive. 

Let's say I have this: 

 StartEnd
member31/1/20191/3/2019
member31/1/20191/4/2019
member312/6/201912/8/2019

 

Here, the answer is 7. 

7 consists of: 1/1, 1/2, 1/3, 1/4, 12/6, and 12/7, and 12/8. 

az38
Community Champion
Community Champion

@bricohen1 

try to create a table

Table Calendar = 
ADDCOLUMNS(
crossjoin(calendar(min('Table'[Start]);max('Table'[End]));distinct('Table'[Member]));
"is in day";if(calculate(count('Table'[Member]);filter('Table'; 'Table'[Start]<=[Date] && 'Table'[End] >= [Date] && EARLIER('Table'[Member])=[Member]))>0;1;0)
)

then just summarize it:

Table Total = summarize('Table Calendar';'Table Calendar'[Member];"Count";SUM('Table Calendar'[is in day]))

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

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.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.