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! Request now

Reply
man2ma
New Member

How to distinctly count customer IDs that visited a store in a given quarter only

How to distinctly count customer IDs that visited a store in a given quarter only if the same customer ID visited in the previous quarter

 

I have a table

+-----------+----------+--------+-------+---------+
|Customer ID|Visit Date|Category|Product|Served by|
+-----------+----------+--------+-------+---------+
|1001       |03/17/2019|A       |P11    |Jone Doe |
|1003       |03/17/2019|D       |P12    |Jone Doe |
|1006       |03/15/2019|C       |P13    |Jone Doe |
|1009       |03/10/2019|G       |P14    |Jone Doe |
|1011       |12/12/2018|H       |P15    |Foo Bar  |
|1003       |11/11/2018|D       |P16    |Foo Bar  |
|1006       |09/10/2018|C       |P17    |Foo Bar  |
|1009       |10/10/2018|G       |P18    |Foo Bar  |
+-----------+----------+--------+-------+---------+

there are 4 customers but only 2 (1003 and 1009) visited in the previous quarter.

I used DATESINPERIOD but it counts all distinctly between the preceding quarters (I have a designated date table).

 

1st approach

customers_count = CALCULATE(DISTINCTCOUNT[Customer ID],DATESINPERIOD('Calendar'[Date],ENDOFQUARTER('Calendar'[Date]),-2,QUARTER))

2nd Approach

customers_count 2Q = 
VAR customers_count_1 = DISTINCT(FILTER(VALUES(Orders[Customer ID]))
VAR customers_count_2 = CALCULATETABLE(DISTINCT(FILTER(VALUES(Orders[Customer ID]))),
                                DATEADD('Calendar'[Date],-1,QUARTER))
RETURN
COUNTROWS(
          INTERSECT(customers_count_1 ,customers_count_2))
The expected count is 2 for the last quarter.

 

 

1 ACCEPTED SOLUTION
v-cherch-msft
Microsoft Employee
Microsoft Employee

Hi @man2ma 

You may create a calendar table.Then you may get the count after adding a visual level filter.

Filter =
VAR Min_Index =
    CALCULATE (
        MIN ( 'Calendar'[Index] ),
        FILTER (
            ALL ( Customer ),
            Customer[Customer ID] = MAX ( Customer[Customer ID] )
        )
    )
VAR Max_Index =
    CALCULATE (
        MAX ( 'Calendar'[Index] ),
        FILTER (
            ALL ( Customer ),
            Customer[Customer ID] = MAX ( Customer[Customer ID] )
        )
    )
RETURN
    IF ( Max_Index - Min_Index = 1, 1 )
Count = DISTINCTCOUNT(Customer[Customer ID])

1.png

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-cherch-msft
Microsoft Employee
Microsoft Employee

Hi @man2ma 

You may create a calendar table.Then you may get the count after adding a visual level filter.

Filter =
VAR Min_Index =
    CALCULATE (
        MIN ( 'Calendar'[Index] ),
        FILTER (
            ALL ( Customer ),
            Customer[Customer ID] = MAX ( Customer[Customer ID] )
        )
    )
VAR Max_Index =
    CALCULATE (
        MAX ( 'Calendar'[Index] ),
        FILTER (
            ALL ( Customer ),
            Customer[Customer ID] = MAX ( Customer[Customer ID] )
        )
    )
RETURN
    IF ( Max_Index - Min_Index = 1, 1 )
Count = DISTINCTCOUNT(Customer[Customer ID])

1.png

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors