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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
derekmac
Helper I
Helper I

DAX SUM ACTIVE Records Between Start Date and End Date with Selected Date on Line Graph

EmployeeID	Start Date	End Date
1	        01/01/2021	31/12/2021
2	        01/01/2022	31/03/2023
3	        01/08/2023	
4	        01/01/2023	
5	        01/03/2023	31/08/2023

 

For the above scenario I want plot the Total Record Count on a Line Graph that shows me the ongoing Active Records taking into account the Date on the X-Axis and taking into account the Start and End Date of the Employee.
Any help or pointers appreciated!




3 ACCEPTED SOLUTIONS
tamerj1
Super User
Super User

Hi @derekmac 
You need to have a disconnected date table. Your count measure would be:

Count =
SUMX (
    VALUES ( 'Date'[Date] ),
    COUNTROWS (
        FILTER (
            'Table',
            'Table'[Start Date] <= 'Date'[Date]
                && COALESCE ( 'Table'[End Date], TODAY () ) >= 'Date'[Date]
        )
    )
)

 

View solution in original post

@derekmac 
Create a date table and keep it disconnected from the main table (no relationships). It should contain all the dates from minimum start date to the maximum end date. Example

Date = CALENDAR ( MIN ( 'Table'[Start Date] ), MAX ( 'Table'[End Date] ) )

Place 'Date'[Date] in a table visual along with the count measure

Count =
SUMX (
    VALUES ( 'Date'[Date] ),
    COUNTROWS (
        FILTER (
            'Table',
            'Table'[Start Date] <= 'Date'[Date]
                && COALESCE ( 'Table'[End Date], TODAY () ) >= 'Date'[Date]
        )
    )
)

 

View solution in original post

@derekmac 

Please try

Count =
SUMX (
    VALUES ( 'Date'[Date] ),
    SUMX (
        FILTER (
            'Table',
            'Table'[Start Date] <= 'Date'[Date]
                && COALESCE ( 'Table'[End Date], TODAY () ) >= 'Date'[Date]
        ),
        'Table'[Target]
    )
)

View solution in original post

8 REPLIES 8
derekmac
Helper I
Helper I

Hi

Total Prospects = 
SUMX (
    VALUES ( 'Dates'[End of Week] ),
    COUNTROWS (
        FILTER (
            'Prospects',
            'Prospects'[Date Added] <= 'Dates'[End of Week]
                && COALESCE ( Prospects[Date Closed], TODAY () ) >= 'Dates'[End of Week]
       )
    )
)

 

How would I amend the above to calculate only for the last 7 days? 

Hi @derekmac 

please clarify with some screenshots 

derekmac
Helper I
Helper I

I don't understand that

@derekmac 
Create a date table and keep it disconnected from the main table (no relationships). It should contain all the dates from minimum start date to the maximum end date. Example

Date = CALENDAR ( MIN ( 'Table'[Start Date] ), MAX ( 'Table'[End Date] ) )

Place 'Date'[Date] in a table visual along with the count measure

Count =
SUMX (
    VALUES ( 'Date'[Date] ),
    COUNTROWS (
        FILTER (
            'Table',
            'Table'[Start Date] <= 'Date'[Date]
                && COALESCE ( 'Table'[End Date], TODAY () ) >= 'Date'[Date]
        )
    )
)

 

Target

1

2

3

4

5

 

If I had a 4th Column called Target, how would I change the DAX to sum this column using the disconnected table instead of Counting Rows?

I want to add a target line to my Line Graph too

Thank you so much for you help so far, I have not come across this technique before, it is quite advanced for me!

@derekmac 

Please try

Count =
SUMX (
    VALUES ( 'Date'[Date] ),
    SUMX (
        FILTER (
            'Table',
            'Table'[Start Date] <= 'Date'[Date]
                && COALESCE ( 'Table'[End Date], TODAY () ) >= 'Date'[Date]
        ),
        'Table'[Target]
    )
)

Thank you so much

tamerj1
Super User
Super User

Hi @derekmac 
You need to have a disconnected date table. Your count measure would be:

Count =
SUMX (
    VALUES ( 'Date'[Date] ),
    COUNTROWS (
        FILTER (
            'Table',
            'Table'[Start Date] <= 'Date'[Date]
                && COALESCE ( 'Table'[End Date], TODAY () ) >= 'Date'[Date]
        )
    )
)

 

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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