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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

DISTINCTCOUNT taking up too much memory

Hi, I have a distinctcount calculated column on a summarized table "Summary" which is taking too long to compute (my computer runs out of memory before it can finish). Please can someone help me find a way to make this work more efficiently? Thank you.

 

DISTINCTCOUNT_USERS =
calculate(distinctcount(Table1[UserID]),
filter(Table1,Table1[Code]=Summary[Code]),
filter(Table2,Table2[Status]="Completed"),
filter(Table2,Table2[EventDate]=Summary[Date]))

(Table1 and Table2 are related)
1 ACCEPTED SOLUTION

Hi @Anonymous 

 

You can use TREATAS as below if it's still too slow, consider moving the calculation to Power Query.

 

DISTINCTCOUNT_USERS_ = 
VAR __filter = { ( Summary[Code], Summary[Date], "Completed" ) }
RETURN 
CALCULATE(
    DISTINCTCOUNT( Table1[UserID] ),
    TREATAS( 
        __filter, 
        Table1[Code], Table2[EventDate], Table2[Status]
    )
)

 

 

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous ,
Try if this can work better

countx(summarize(calculatetable(Table1,
filter(Table1,Table1[Code]=Summary[Code]),
filter(Table2,Table2[Status]="Completed"),
filter(Table2,Table2[EventDate]=Summary[Date])),Table1[UserID])[UserID])
Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @Anonymous 

 

You can use TREATAS as below if it's still too slow, consider moving the calculation to Power Query.

 

DISTINCTCOUNT_USERS_ = 
VAR __filter = { ( Summary[Code], Summary[Date], "Completed" ) }
RETURN 
CALCULATE(
    DISTINCTCOUNT( Table1[UserID] ),
    TREATAS( 
        __filter, 
        Table1[Code], Table2[EventDate], Table2[Status]
    )
)

 

 

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Anonymous
Not applicable

Hi @amitchandak are you sure the brackets etc. are in the right place? Power BI doesn't like that code

@Anonymous  one , was missing

countx(summarize(calculatetable(Table1,
filter(Table1,Table1[Code]=Summary[Code]),
filter(Table2,Table2[Status]="Completed"),
filter(Table2,Table2[EventDate]=Summary[Date])),Table1[UserID]),[UserID])
Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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