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
PBIX_COACH
Helper II
Helper II

Customer Count by Active Years

Hello Team I need some assistance getting a DAX formula to work for this. I have two tables (Customers sales table and Calendar table) connected by the date field and I would like to get a count of the total active years for that customer.

 

 

Screenshot 2023-03-22 051309.png

Any assistance would be greatly appreciated.

 

Thanks

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @PBIX_COACH 
You can use the matrix total column to present the Total Active Years (You can simply rename it). You need to replace the current measure (Measure1) with the following

Measure2 =
IF (
    ISINSCOPE ( 'Date'[Year] ),
    [Measure1],
    COUNTX ( VALUES ( 'Date'[Year] ), [Measure1] )
)

View solution in original post

5 REPLIES 5
PBIX_COACH
Helper II
Helper II

@tamerj1  nevermind, my misunderstanding I got it now! thanks so much

tamerj1
Super User
Super User

Hi @PBIX_COACH 
You can use the matrix total column to present the Total Active Years (You can simply rename it). You need to replace the current measure (Measure1) with the following

Measure2 =
IF (
    ISINSCOPE ( 'Date'[Year] ),
    [Measure1],
    COUNTX ( VALUES ( 'Date'[Year] ), [Measure1] )
)

@tamerj1  on another note how can I flag if there was a "win back" for example company A had a gap year in 2021 but returned in 2022?

@PBIX_COACH 
Please try

Measure2 =
IF (
    ISINSCOPE ( 'Date'[Year] ),
    [Measure1],
    VAR T1 =
        ADDCOLUMNS ( VALUES ( 'Date'[Year] ), "@Value", [Measure1] )
    VAR T2 =
        FILTER ( T1, [@Value] <> BLANK () )
    RETURN
        "Total Active Years: " & COUNTROWS ( T2 )
            & UNICHAR ( 10 ) & "Win Back Years: "
            & SUMX ( T2, INT ( ISEMPTY ( FILTER ( T2, [Year] = EARLIER ( [Year] ) - 1 ) ) ) )
)

thanks for the assist @tamerj1  but it's returning the total count for all companies by the year but I'm looking for the unique count of years. for example, company A has an activity for 3 years because it has data in 2019, 2020 and 2022 so it should return a total of 3 years active.

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.