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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
vamsikb
Frequent Visitor

New Column to Count Distinct a text field partitioned on another field

Following is my current table with the first 2 columns (Group By and To Count):

 

Group byTo CountNew Column
AXYZ2
AXYZ2
AMNO2
BMNO3
BGHK3
BTRP3

 

I'm trying to add the new column which partitions the table by "Group by" column and finds distinct count of "To Count" column. This new column needs to be used for another calculation, hence it should be static value across the table. What's the best way to achieve this?

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

Allexcept is used to get the partitioned by

 

 

Refer this ia a good example

https://community.powerbi.com/t5/Desktop/highest-value-by-category/td-p/428758

Try

New Column =
    CALCULATE (
        count ( 'Table'[To Count] ),
        ALLEXCEPT ( 'Table', 'User Table'[Group by] )
    )

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Write this calculated column formula

=CALCULATE(DISTINCTCOUNT(Data[To Count]),FILTER(Data,Data[Group By]=EARIER(Data[Group By])))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

Allexcept is used to get the partitioned by

 

 

Refer this ia a good example

https://community.powerbi.com/t5/Desktop/highest-value-by-category/td-p/428758

Try

New Column =
    CALCULATE (
        count ( 'Table'[To Count] ),
        ALLEXCEPT ( 'Table', 'User Table'[Group by] )
    )

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.