Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Calculate percentage on direct query

Hi all (:

I would appreciate your help.

I want to calculate a percentage on direct query.

 

I calc the count(*) "country" and I an not succeed to calculate the percentage

 

The data :

Country        color of the flag  

--------------------------------
USA                 red              
USA                 white              
USA                 blue                
Greece            White 
Greece            blue

The The desired result:

Country         sum(count())   Percent%

USA                  3                    60%

Greece              2                    40%

 

Thanks,

sin

 

 
  • Hi Anonymous 

    A little change based Rocco_sprmnt21 query, delete *100, after close &&apply, change the data column to "percentage" format.

    Also, since it is direct query mode, you could also try to create a measure like:

    Measure 3 =
    CALCULATE (
        COUNT ( 'Table 2'[color of flag] ),
        ALLEXCEPT (
            'Table 2',
            'Table 2'[Country]
        )
    )
        / CALCULATE (
            COUNT ( 'Table 2'[color of flag] ),
            ALL ( 'Table 2' )
        )
    

    Best Regards
    Maggie
    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    try somethink like this:

     

    grp= Table.Group(tab, {"Country "}, {{"Conteggio", each Table.RowCount(_), type number}}),
    pc = Table.AddColumn(grp, "Percentuale di", each [Conteggio] / List.Sum(grp[Conteggio]) * 100, type number)

     

  • v-juanli-msft's avatar
    v-juanli-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous 

    A little change based Rocco_sprmnt21 query, delete *100, after close &&apply, change the data column to "percentage" format.

    Also, since it is direct query mode, you could also try to create a measure like:

    Measure 3 =
    CALCULATE (
        COUNT ( 'Table 2'[color of flag] ),
        ALLEXCEPT (
            'Table 2',
            'Table 2'[Country]
        )
    )
        / CALCULATE (
            COUNT ( 'Table 2'[color of flag] ),
            ALL ( 'Table 2' )
        )
    

    Best Regards
    Maggie
    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.