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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
nikostou
Regular Visitor

Counting and summing days in periods, disregarding duplicates

Hi,

 

I am trying to get an overview of the number of days my resources has been running in a given period (eg. week or month).

 

My data looks similar to this:

ResourceIDStartDateEndDate
KF4101205-11-202108-11-2021
SL5121510-11-202115-11-2021
KF4140008-11-202111-11-2021
BV2158913-11-202116-11-2021
BV2136516-11-202120-11-2021
KF4148514-11-202120-11-2021
NI8135401-11-202114-11-2021
SL5184520-11-202122-11-2021
NI8124516-11-202119-11-2021
SL5178422-11-202122-11-2021
BV2123525-11-202130-11-2021

 

The biggest issue here is that I want to count the days of work, but if two IDs overlap, the day should only be counted once.

 

The result I would like to have should be something like this:

ResourceDays of work
KF414
SL59
BV214
NI818

 

Please let me know if you have any ideas!

Thank you 🙂 

9 REPLIES 9
VahidDM
Super User
Super User

Hi @nikostou 

 

If you want to disregarding overlaps, try this code:

** I added new rows to youe sample data to create overlaps, my table is as below:

VahidDM_0-1641514229626.png

 

 

Code:

Days of work =
VAR _RES =
    VALUES ( 'Table'[Resource] )
VAR _DT =
    CALENDAR ( MIN ( 'Table'[StartDate] ), MAX ( 'Table'[EndDate] ) )
VAR _DTA =
    CROSSJOIN ( _RES, _DT )
VAR _RD =
    ADDCOLUMNS (
        _DTA,
        "In",
            CALCULATE (
                COUNTROWS ( 'Table' ),
                FILTER (
                    'Table',
                    'Table'[Resource] = EARLIER ( [Resource] )
                        && 'Table'[StartDate] <= [Date]
                        && 'Table'[EndDate] >= [Date]
                )
            )
    )
VAR _RDWB =
    FILTER ( _RD, [In] <> BLANK () )
RETURN
    COUNTROWS ( _RDWB )

 

 

result:

VahidDM_1-1641514277369.png

 

 

Download file: https://gofile.io/d/HUTAzY

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Hi @Anonymous 
Unfortunately I cannot get this to give me the right result.

Samarth_18
Community Champion
Community Champion

Hi @nikostou ,

 

Create a column with below code:-

Column = DATEDIFF('Table'[StartDate],'Table'[EndDate],DAY)

 

Now create a measure with below code:-

Measure = SUM('Table'[Column])+2

 

Output:-

Samarth_18_0-1641490062950.png

 

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Hi @Samarth_18 

 

Unfortunately this does not work.

 

I am not sure why you are adding 2 in the measure?

Can you explain that to me?

smpa01
Super User
Super User

@nikostou  I don't see any overlapping IDs here in the sample and therefore I don't think it is represtative of the issue you described.

 

Can you please provide something that is represtative of the challenge you described.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi @smpa01 

 

It is overlapping in the sense that if one resource ends one ID and starts another, then this day/date should not be counted twice.

If I make a measure that counts the days of work per line and then simply sums it up at the end, then in this case this date/day will be counted twice.

Like this:

ResourceIDStartDateEndDateWorking days
KF4101205-11-202108-11-20214
SL5121510-11-202115-11-20216
KF4140008-11-202111-11-20214
BV2158913-11-202116-11-20214
BV2136516-11-202120-11-20215
KF4148514-11-202120-11-20217
NI8135401-11-202114-11-202114
SL5184520-11-202122-11-20213
NI8124516-11-202119-11-20214
SL5178422-11-202122-11-20211
BV2123525-11-202130-11-20216

 

The wrong result would look like this:

ResourceDays of workSum of working days
KF41415
SL5910
BV21415
NI81818

 

Days of work is the days that the resource has been working.

Sum of working days is summing the individual count of days pr. line.

 

Days of work is the result I am looking for.

@nikostou  this will give you what you need

Measure = 
COUNTROWS (
    SUMMARIZE (
        GENERATE (
            'Table',
            DATESBETWEEN ( 'Calendar'[Date], 'Table'[StartDate], 'Table'[EndDate] )
        ),
        'Table'[Resource],
        'Calendar'[Date]
    )
)

 

 

smpa01_0-1641564867396.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi @smpa01

 

Unfortunately this does not work.

 

If a resource has more IDs one one day, this will count these days multiple times.

This is wrong..

@nikostou provide sample data accordingly

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.