Forum Discussion
Group by and count in scatter plot
- 4 years ago
You'd need to create a table that contains all possible sessions per user.
Something like this:
X-Axis = VAR MaxSessions = MAXX ( ALL ( Sessions[user_id] ), CALCULATE ( COUNT ( Sessions[id] ) ) ) RETURN SELECTCOLUMNS ( GENERATESERIES ( 0, MaxSessions + 1 ), "Sessions", [Value] )The measures have to be a bit more complicated.
AvgUniqueContent = VAR CurrSessions = SELECTEDVALUE ( 'X-Axis'[Sessions] ) VAR Summary = SUMMARIZE ( Sessions, Sessions[user_id], "@UniqueContent", DISTINCTCOUNT ( Sessions[content_id] ), "@Sessions", COUNT ( Sessions[id] ) ) RETURN AVERAGEX ( FILTER ( Summary, [@Sessions] = CurrSessions ), [@UniqueContent] )The user count can be defined similarly (just use COUNTROWS instead of AVERAGEX in the last line).
This is easier if you create a calculated summary table like this:
From there, it's drag-and-drop to put the fields into a scatterplot.
If it needs to be more dynamic (where a calculated table doesn't work), you'll still need to create an extra table to use for the x-axis.
- Bart_Berg4 years agoFrequent Visitor
Thanks a lot for your detailed answer, it's very much appreciated! This does work indeed, but unfortunately I need to be able to filter on month even and even on a category which is in another dimension linked by content_id. What would my table structure need to look like to make that work?
Thanks :)!
- AlexisOlson4 years agoSuper User
You'd need to create a table that contains all possible sessions per user.
Something like this:
X-Axis = VAR MaxSessions = MAXX ( ALL ( Sessions[user_id] ), CALCULATE ( COUNT ( Sessions[id] ) ) ) RETURN SELECTCOLUMNS ( GENERATESERIES ( 0, MaxSessions + 1 ), "Sessions", [Value] )The measures have to be a bit more complicated.
AvgUniqueContent = VAR CurrSessions = SELECTEDVALUE ( 'X-Axis'[Sessions] ) VAR Summary = SUMMARIZE ( Sessions, Sessions[user_id], "@UniqueContent", DISTINCTCOUNT ( Sessions[content_id] ), "@Sessions", COUNT ( Sessions[id] ) ) RETURN AVERAGEX ( FILTER ( Summary, [@Sessions] = CurrSessions ), [@UniqueContent] )The user count can be defined similarly (just use COUNTROWS instead of AVERAGEX in the last line).
- Bart_Berg4 years agoFrequent Visitor
That's awesome, thanks again for the detailed explanation. This works great!!