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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Rathod
Frequent Visitor

DAX expression to find the previous all customers count from the current selection date

Hi All,

 

Can anyone help me to get the DAX expression to find the Distinctcount of customers for the past years from the current selection year.

Example : I have customer table with, customer id and year .

Customer ID | Year
11 - 2020
22 - 2020
33 - 2020
11 - 2020
22 - 2020
44 - 2020
77 - 2021
11 - 2021
88 - 2021
99 - 2021
100 - 2022
22 - 2022
101 - 2022
102 - 2023
103 - 2023


Now, if i select 2022 year in slicer o/p should get : 9

2 REPLIES 2
Rathod
Frequent Visitor

Hi, @Anonymous 

Thanks  for your DAX expression, but o/p should get 9 not 8, anyway i found the expression below.

Customer Count =
VAR maxYear = MAX( 'Table'[Year] )
RETURN
CALCULATE(
DISTINCTCOUNT( 'Table'[Customer ID] ),
'Table'[Year] <= maxYear
)

Anonymous
Not applicable

Hi @Rathod ,

Please try to create a measure with below dax formula:

Measure =
VAR _year =
    SELECTEDVALUE ( 'Table'[Year] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), [Year] < _year )
VAR tmp1 =
    SUMMARIZE ( tmp, [Year], [Customer ID] )
RETURN
    COUNTROWS ( tmp1 )

vbinbinyumsft_0-1682472272125.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.