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
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])

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])

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.