Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@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!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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

 

 

Greg, can you assist?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.