Forum Discussion

MichiyoTora's avatar
MichiyoTora
Frequent Visitor
1 year ago
Solved

Repartition by max activity

Hi ! I've data like this : My goal is to have a pie shart to show the repartition of the members by their most used activity like this : I tried a lot of things to do this but I didn...
  • johnt75's avatar
    johnt75
    1 year ago

    This works if you use columns from the dimension table rather than the activity table

    Count members with main activity type = 
    VAR CurrentType =
        SELECTEDVALUE ( Activities[type] )
    VAR BaseTable =
        ADDCOLUMNS (
            CALCULATETABLE (
                SUMMARIZE ( activity, Users[account], Activities[type] ),
                REMOVEFILTERS ( Activities[type] )
            ),
            "@sum", CALCULATE (COUNTROWS( activity ) )
        )
    VAR PartitionedTable =
        INDEX (
            1,
            BaseTable,
            ORDERBY ( [@sum], DESC ),
            PARTITIONBY ( Users[account] )
        )
    VAR Types =
        GROUPBY (
            PartitionedTable,
            Activities[type],
            "@users", SUMX ( CURRENTGROUP (), 1 )
        )
    VAR Result =
        SUMX ( FILTER ( Types, Activities[type] = CurrentType ), [@users] )
    RETURN
        Result