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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
aellison
Helper I
Helper I

Calculate Distinct Customers by Year based on Start and End Dates

I'm trying to find the correct expression to return DISTINCT counts of customers by Fiscal Year. Blank end dates means that they are current customers. Customers can be in multiple programs at one time, but should still only be counted as a single distinct customer. Here is an example of the dataset:

 

CustomerIDProgramIDStartDateEndDateFiscal Year StartFiscal Year End
11111/1/2013 2013 
22211/1/20147/1/201420142015
33311/1/2016 2016 
44416/1/201412/31/201520142015
33322/1/20165/1/201620162016

 

Here is the output that is needed:

 

Fiscal Year# of Customers
20131
20143
20153
20162
1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @aellison,

 

You could use an 'events in progress' measure.

 

Here is a sample PBIX file, using your sample data, with 3 different definitions of the measure:

https://www.dropbox.com/s/m7idfw64eborw5w/Distinct%20Customers%20in%20Program.pbix?dl=1

 

Note: From your sample data it looked like you have a July-June fiscal year, so I got 3 distinct customers in Fiscal Year 2016 (since 444 extends into FY 2016).

 

Here is one of the measures:
(note, the measure assumes you might have a relationship between CustomerProgram and Calendar tables):

 

Distinct Customers in Program  v3 = 
CALCULATE (
    CALCULATE ( DISTINCTCOUNT ( CustomerProgram[CustomerID] ), ALL ( 'Calendar' ) ),
    GENERATE (
        CALCULATETABLE (
            SUMMARIZE (
                CustomerProgram,
                CustomerProgram[CustomerID],
                CustomerProgram[StartDate],
                CustomerProgram[EndDate]
            ),
            ALL ( 'Calendar' )
        ),
        INTERSECT (
            DATESBETWEEN (
                'Calendar'[Date],
                CustomerProgram[StartDate],
                CustomerProgram[EndDate]
            ),
            VALUES ( 'Calendar'[Date] )
        )
    )
)

 

The measure is based on DAX code from this paper (page 27):

http://www.sqlbi.com/wp-content/uploads/DAX-Query-Plans.pdf

 

Regards,

Owen 🙂


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

3 REPLIES 3
OwenAuger
Super User
Super User

Hi @aellison,

 

You could use an 'events in progress' measure.

 

Here is a sample PBIX file, using your sample data, with 3 different definitions of the measure:

https://www.dropbox.com/s/m7idfw64eborw5w/Distinct%20Customers%20in%20Program.pbix?dl=1

 

Note: From your sample data it looked like you have a July-June fiscal year, so I got 3 distinct customers in Fiscal Year 2016 (since 444 extends into FY 2016).

 

Here is one of the measures:
(note, the measure assumes you might have a relationship between CustomerProgram and Calendar tables):

 

Distinct Customers in Program  v3 = 
CALCULATE (
    CALCULATE ( DISTINCTCOUNT ( CustomerProgram[CustomerID] ), ALL ( 'Calendar' ) ),
    GENERATE (
        CALCULATETABLE (
            SUMMARIZE (
                CustomerProgram,
                CustomerProgram[CustomerID],
                CustomerProgram[StartDate],
                CustomerProgram[EndDate]
            ),
            ALL ( 'Calendar' )
        ),
        INTERSECT (
            DATESBETWEEN (
                'Calendar'[Date],
                CustomerProgram[StartDate],
                CustomerProgram[EndDate]
            ),
            VALUES ( 'Calendar'[Date] )
        )
    )
)

 

The measure is based on DAX code from this paper (page 27):

http://www.sqlbi.com/wp-content/uploads/DAX-Query-Plans.pdf

 

Regards,

Owen 🙂


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn
ankitpatira
Community Champion
Community Champion

@aellison Under Modelling tab, click New Table and create as below,

 

=SUMMARIZE(tableName, tableName[Fiscal Year Start],"a",DISTINCTCOUNT(tableName[CustomerID]) )

Hi @ankitpatira,

 

Thank you for the quick response. I am performing this within an SSAS Tabular Model ... is your suggestion for Excel only?

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors