cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sguenther
Advocate II
Advocate II

Cohort Analysis

Hello,

 

I would like to create a cohort analysis, showing the activity of users (grouped by signup month) over time. Therefore I could use the custom Heat-map visualization. The only thing I need is a table showing the number logins by user groups for each month. I was able to set this up in excel, but I'm relatively new to DAX, so I'm not really sure how to do this.

 

What I have is a table with all logins and the the user signup date (transformed to startofmonth) for each login (and created an additional column (cohort) which gives me the cohort number: 1 (for Jan 14) - 23 (for Nov 15). I set up a custom table with all the cohorts and the start dates of each cohort. I also created another seperate date table and linked all three via date. I set up a measure:

 

Activity per Month= CALCULATE(COUNTA('activity'[login]), FILTER(ALL(Dates[Date]), AND((YEAR(Dates[Date]) = MAX(Dates[Year])) , (MONTH(Dates[Date]) = MAX(Dates[Month])))))

 

This gives me the number of logins per Month. But what i need is the number of logins for each cohort. My idea was to set up a measure for each cohort. But I don't know how to set up the filter correctly. I think that I need to filter in the date table and the activity table (for the cohort). Something like this:

 

Activity per Month cohort 1= CALCULATE(COUNTA('activity'[login]), FILTER('activity'[login] , 'activity'[cohort] =  1) && FILTER(ALL(Dates[Date]), AND((YEAR(Dates[Date]) = MAX(Dates[Year])) , (MONTH(Dates[Date]) = MAX(Dates[Month])))))

 

But of course this doesn't work. Any ideas?

1 ACCEPTED SOLUTION

You could try:

Activity per Month cohort 1= CALCULATE(COUNTAX('activity'[login], 'activity'[cohort] =  1), AND((YEAR(Dates[Date]) = MAX(Dates[Year])) , (MONTH(Dates[Date]) = MAX(Dates[Month]))))

 

Might have an extra paren in there. Can't be sure unless I have some mock data to build a data model with and test.

 


@ me in replies or I'll lose your thread!!!
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Learn Power BI 2nd Edition

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

These types of questions are far easier to answer if you can post some sample data and what your desired output is for that sample data. In general, I would not recommend trying to filter by individual cohort. In theory, you could use your current measure and simply create a table with cohort and that measure and your measure should be context filtered to give you a count of logins by cohort.


@ me in replies or I'll lose your thread!!!
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Learn Power BI 2nd Edition

@Greg_Deckler: thx for the quick reply. Unfortunately I can't share my data here due to confidentiality reasons. But I could share a mockup of my data if needed. But actually this is just a DAX related question. I also think that I should be able to use my current measure, but I need to insert this additional filter correctly. And I just don't knwo how to do it in DAX. Basically what I need to do is to add a Filter which filters the argument of my COUNTA function.

You could try:

Activity per Month cohort 1= CALCULATE(COUNTAX('activity'[login], 'activity'[cohort] =  1), AND((YEAR(Dates[Date]) = MAX(Dates[Year])) , (MONTH(Dates[Date]) = MAX(Dates[Month]))))

 

Might have an extra paren in there. Can't be sure unless I have some mock data to build a data model with and test.

 


@ me in replies or I'll lose your thread!!!
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Learn Power BI 2nd Edition

i am also having issues on how to start with cohort analysis on power bi.

 

 

Greg, can you assist?

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors