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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Twitter
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
Twitter
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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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