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
naseem_1973
Helper I
Helper I

%age require a text coulmn

Dear All,

 

I have a text-based column consisting of different categories of calls in my table. I want to calculate the percentage of each category in this column.

I've tried using distinct count and regular count, but the results are not accurate.

 

sample.png

3 ACCEPTED SOLUTIONS
eliasayyy
Super User
Super User

Cout = COUNTROWS('Table')
Count All = COUNTROWS('ALL('Table')
Count Per = DIVIDE([Count],[Count All])

View solution in original post

Prateek97
Resolver III
Resolver III

Hi @naseem_1973 ,

 

Hope this works for you.

 

Measure = COUNT(CTable[Category])/CALCULATE(COUNT(CTable[Category]),ALL(CTable[Category]))

 

Prateek97_0-1692340828457.png

 

View solution in original post

Okey, I have just realized why!!!

 

You are using a var as the name of the function. Var is used to store values (https://learn.microsoft.com/en-us/dax/var-dax).  Take a look at my code, the name is % of communications. I will paste it again:

 

 

% of communications = 

var allValues= CALCULATE([Total communications],ALLSELECTED(MyTable[Communication Method]))
return DIVIDE([Total communications],allValues,0)

 


BTW, variables are really useful in Power BI to improve readability and performance sometimes (https://learn.microsoft.com/en-us/dax/best-practices/dax-variables). 

View solution in original post

8 REPLIES 8
Prateek97
Resolver III
Resolver III

Hi @naseem_1973 ,

 

Hope this works for you.

 

Measure = COUNT(CTable[Category])/CALCULATE(COUNT(CTable[Category]),ALL(CTable[Category]))

 

Prateek97_0-1692340828457.png

 

eliasayyy
Super User
Super User

Cout = COUNTROWS('Table')
Count All = COUNTROWS('ALL('Table')
Count Per = DIVIDE([Count],[Count All])

mlsx4
Super User
Super User

Hi @naseem_1973 

 

Try this:

 

Total communications = COUNTROWS(MyTable)
% of communications = 

var allValues= CALCULATE([Total communications],ALL(MyTable))
return DIVIDE([Total communications],allValues,0)

 

If you want to be able to filter and keep being 100%, use this:

% of communications = 

var allValues= CALCULATE([Total communications],ALLSELECTED(MyTable[Communication Method]))
return DIVIDE([Total communications],allValues,0)

 

Sir , its showin error

 

 

Hi @naseem_1973 

 

I don't know why, because for me it's working perfectly. If you select some of the values:

mlsx4_0-1692345428337.png

 

If there's nothing selected:

mlsx4_1-1692345454603.png

 

In fact, my solution also considers the possibility of catching errors while dividing

Please check where I doing mistake.

naseem_1973_0-1692346981651.png

 

Okey, I have just realized why!!!

 

You are using a var as the name of the function. Var is used to store values (https://learn.microsoft.com/en-us/dax/var-dax).  Take a look at my code, the name is % of communications. I will paste it again:

 

 

% of communications = 

var allValues= CALCULATE([Total communications],ALLSELECTED(MyTable[Communication Method]))
return DIVIDE([Total communications],allValues,0)

 


BTW, variables are really useful in Power BI to improve readability and performance sometimes (https://learn.microsoft.com/en-us/dax/best-practices/dax-variables). 

Thanks,

 

its working 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.