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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
vin26
Resolver I
Resolver I

Issue with DistinctCount Custom Column Calculation

Hello,

I have huge data table (more than 50 million rows) on which I have created below Column and measure. Column Calculation works fine when I use COUNT but not working when I use DISTINCTCOUNT, it just showing 'Working on it..". Could you please someone help me with alternative to the column calculation or replicate column calculation in measure.

 

Sample Table:

MonthEMPIDVisitID
Mar-24A111V123
Mar-24A111V123
Mar-24A111V345
Mar-24A111V345
Mar-24A111V222
Mar-24A111V333
Mar-24A222V56
Mar-24A222V678
Mar-24A222V456
Mar-24A222V456
Mar-24A222V444
Mar-24A333V696
Mar-24A333V686
Mar-24A333V900
Mar-24A333V900
Mar-24A333V222
Mar-24A333V234
Mar-24A333V234

 

Custom Column:

 

 

Column = Var NoOfOccurrences = CALCULATE (
    DISTINCTCOUNT( Table1[VisitID]),
    FILTER (
        Table1,
        Table1[VisitID] = EARLIER ( Table1[VisitID] ) &&
        Table1[Month] = EARLIER ( Table1[Month] ) &&
        Table1[EMPID] = EARLIER( Table1[EMPID])
    )
)
RETURN
IF(NoOfOccurrences >= 2, "A", IF(NoOfOccurrences = 1, "B", BLANK()))

 

 

 

Measure:

 

 

Measure =CALCULATE( DISTINCTCOUNT (Table1[EMPID]), FILTER(Table1, Table1[Column] = “A”))

 

 

 

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @vin26 -Instead of creating a calculated column, it's better to replicate the logic in a measure, as measures are calculated dynamically and can handle large datasets more efficiently than columns.

 

MeasureColumnLogic =
VAR NoOfOccurrences =
CALCULATE(
DISTINCTCOUNT(Table1[VisitID]),
ALLEXCEPT(Table1, Table1[Month], Table1[EMPID])
)
RETURN
IF(NoOfOccurrences >= 2, "A", IF(NoOfOccurrences = 1, "B", BLANK()))

 

You can now use this measure in your final calculation with the above combination.

 

Measure =
CALCULATE(
DISTINCTCOUNT(Table1[EMPID]),
FILTER(
Table1,
[MeasureColumnLogic] = "A"
)
)

 

Hope this works in your scenerio





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

1 REPLY 1
rajendraongole1
Super User
Super User

Hi @vin26 -Instead of creating a calculated column, it's better to replicate the logic in a measure, as measures are calculated dynamically and can handle large datasets more efficiently than columns.

 

MeasureColumnLogic =
VAR NoOfOccurrences =
CALCULATE(
DISTINCTCOUNT(Table1[VisitID]),
ALLEXCEPT(Table1, Table1[Month], Table1[EMPID])
)
RETURN
IF(NoOfOccurrences >= 2, "A", IF(NoOfOccurrences = 1, "B", BLANK()))

 

You can now use this measure in your final calculation with the above combination.

 

Measure =
CALCULATE(
DISTINCTCOUNT(Table1[EMPID]),
FILTER(
Table1,
[MeasureColumnLogic] = "A"
)
)

 

Hope this works in your scenerio





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





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.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors