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
aleary78
New Member

How to do distinct count by time period with a DAX measure

I have a dimension table with column Account ID

Account ID
a
b
c

 

and fact table linked by Account ID

MerchantAccount IDDateValue
1aJanuary500
2aFebruary100
2bFebruary300
2cJanuary200
3aJanuary900
3bFebruary400

I am looking to create a measure that would be used in a table that would show for each merchant, how many accounts have used it in a selected time period (e.g. YTD)

 

so for February YTD it would show:

MerchantNumber of Accounts
11
23
32

 

but for January YTD it would show:

MerchantNumber of Accounts
11
21
31

 

I have thus far got the following:
YTD count = CALCULATE(COUNTROWS(FILTER(VALUES(Dim[Account ID]),CALCULATE(SUM(Fact[Value])>0),ALL('Dates'),DATESYTD('Dates'[Date]))

 

Unfortunately due to the high cardinality of the Merchant column in the dimension table and millions of records, it is exceeding the available resources.

 

Please could I be guided on how to make the measure more efficient

1 ACCEPTED SOLUTION
mdaatifraza5556
Super User
Super User

Hi @aleary78 

Can you please try the below dax to get your result ?

Create only one measure to count using below dax.

 

Accounts Count YTD =
CALCULATE (
    DISTINCTCOUNT ( fact_table[Account ID] ),
    DATESYTD ( 'dim_date'[Date] )
)
 
 
Result
 
 
When Feb is selected
 
Screenshot 2025-08-19 122617.png

 

When Jan is selected 
Screenshot 2025-08-19 122630.png

 

 

If this answers your questions, kindly accept it as a solution and give kudos.

 

I have also attached the pbix file for your reference.

View solution in original post

10 REPLIES 10
mdaatifraza5556
Super User
Super User

Hi @aleary78 

Can you please try the below dax to get your result ?

Create only one measure to count using below dax.

 

Accounts Count YTD =
CALCULATE (
    DISTINCTCOUNT ( fact_table[Account ID] ),
    DATESYTD ( 'dim_date'[Date] )
)
 
 
Result
 
 
When Feb is selected
 
Screenshot 2025-08-19 122617.png

 

When Jan is selected 
Screenshot 2025-08-19 122630.png

 

 

If this answers your questions, kindly accept it as a solution and give kudos.

 

I have also attached the pbix file for your reference.

Hi @mdaatifraza5556 this also gives me the total number of accounts which makes me think there is something wrong with my schema. I will see if I can determine. Having said that, my orignial formula worked when I selected a subset of merchants. Unfortunately I am not able to share pbix externally

Hi @aleary78 

You can refer the pbix file which i have shared.

try to make the schema as you can see in the pbix file.


Make 1 to * connection ( dim_date ---- fact table using date column)

Make 1 to * connection ( dim_id ---- fact table uisng acount_id )


Create month column in your dim_date table



If this does not work then please provide sample dataset which relates to your data.

If this answers your questions, kindly accept it as a solution and give kudos.

Hi @mdaatifraza5556  I believe your answer is correct as your file shows this so happy to give kudos. Unfortunatley I am not able to share pbix. Can you see if you can spot anything visibily wrong with my schema below? The MCA Details table is the dimension table I was referring to and the CV table is the fact table. 

aleary78_0-1755588631921.png

 

Hi @aleary78 

Make sure that 

there is no any filter or slicer is applied from the table which i have circile.

Please remove every filter or the slicer is applied from that table for testing purpose
and then check it.


Or Just remove every slicer and filter ( keep only for date table to select month)


Then try to validate.

Or if you are able to create some sample data exactily as your schema then i can try from my end.


Screenshot 2025-08-19 141454.png

 

 

If this answers your questions, kindly accept it as a solution and give kudos.

Hi @mdaatifraza5556 I have inputted my numbers into your file. It would appear that I need to store account ID in the fact table too and distinct count there. I believe this is to do with the structure of my databetween the CV table and the Tagging table in my image, but I need to keep that for other reasons. Thank you for your guidance. Should work perfectly now

aleary78
New Member

Hi @jaineshp this seems to give me the count of all accounts unfortunately

Hello @aleary78, the comment you responded to has been removed.

 

Best,

Natalie H.

Community Manager 

aleary78
New Member

Hi @jaineshp the function "EXISTS" doesn't appear to be available to use in a DAX measure in PowerBI. it has a red squiggle underneath it

Hello @aleary78the comment you responded to has been removed.

 

Best,

Natalie H.

Community Manager 

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.