Forum Discussion

naseem_1973's avatar
naseem_1973
Helper I
3 years ago
Solved

%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 ...
  • eliasayyy's avatar
    3 years ago

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

  • Prateek97's avatar
    3 years ago

    Hi naseem_1973 ,

     

    Hope this works for you.

     

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

     

     

  • mlsx4's avatar
    mlsx4
    3 years ago

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