Forum Discussion
Repartition by max activity
- 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
You can try
Count members with main activity type =
VAR CurrentType =
SELECTEDVALUE ( activity[type] )
VAR BaseTable =
ADDCOLUMNS (
CALCULATETABLE (
SUMMARIZE ( activity, activity[account], activity[type] ),
REMOVEFILTERS ( activity[type] )
),
"@sum", CALCULATE ( SUM ( activity[number] ) )
)
VAR PartitionedTable =
INDEX (
1,
BaseTable,
ORDERBY ( [@sum], DESC ),
PARTITIONBY ( activity[account] )
)
VAR Types =
GROUPBY (
PartitionedTable,
activity[type],
"@users", SUMX ( CURRENTGROUP (), 1 )
)
VAR Result =
SUMX ( FILTER ( Types, activity[type] = CurrentType ), [@users] )
RETURN
Result
- MichiyoTora1 year agoFrequent Visitor
It seems not working, members still in each type of activity they use, not only the principal one ...
- mark_endicott1 year ago
Super User
MichiyoTora - it would be useful to have some sample data to test but I would structure this like so:
Create a measure called Number of Activity:SUM( activity[number] )Then reference it in an additional measure:
VAR RankedActivities = ADDCOLUMNS ( SUMMARIZE ( activity, activity[account], activity[type] ), "ActivityRank", RANK ( DENSE, ALLSELECTED ( activity[type] ), ORDERBY([Number of Activities], DESC), , PARTITIONBY(activity[account]) ) ) VAR TopActivity = FILTER ( RankedActivities, [ActivityRank] = 1 ) RETURN CALCULATE ( [Number of Activities], TREATAS ( SELECTCOLUMNS ( TopActivity, "account", activity[account] ), TD_members[account] ) )There may be an issue with Ranking in this way inside an add columns, but if you can provide some sample data it would be easier to resolve.
Of course if this works, please accept as the solution. It helps with visibility for others with the same challenge!
- MichiyoTora1 year agoFrequent Visitor
Thank's a lot for your time and your help.
Power BI found a problem with the partitionby part of your measure. I don't know well enough this option to correct it.
Here is a sample of my acticity data, you'll be able to create dimensions tables with values function : https://docs.google.com/spreadsheets/d/1RUHtEUY8Ywsi4vPLvJzk-vh6QSRg6HyOWSWz-PDfFMg/edit?usp=sharing