Forum Discussion
stfox
10 years agoHelper I
DAX: Ranking or Indexing Dates
Hi Folks I have a Pivot that creates a Cohort Anlaysis as shown on the left below. This shows the number of customer remaining in a cohort in the subsequent months (invoice months) following signup...
- 10 years ago
In this scenario, we can rank Invoice Month (from earliest month) within each Signup Month group, and use the rank number as the column group in Matrix. Please refer to following steps:
- Create a measure for the number of customers.
TotalCustomer = CALCULATE(COUNTROWS('Raw Cohort data')) - Since we will rank the month values, we need to convert the Invoice date into number.
Inv_Year&Month = VALUE ( YEAR ( 'Raw Cohort data'[Invoice_Month] ) & "0" & MONTH ( 'Raw Cohort data'[Invoice_Month] ) ) - Create a column for the rank by Inv_Year&Month within Signup month. You can see the rank in below table chart.
RankInvoiceYear&Month = RANKX ( FILTER ( 'Raw Cohort data', EARLIER ( 'Raw Cohort data'[Signup Month] ) = 'Raw Cohort data'[Signup Month] ), 'Raw Cohort data'[Inv_Year&Month], , ASC, DENSE ) - Drag below data fields into the Matrix chart. Since you already know the DAX for the % view, you can replace “RankInvoiceYear&Month” with the % view DAX and then you can get another % view Matrix.
- Create a measure for the number of customers.
v-sihou-msft
10 years agoMicrosoft Employee
In this scenario, we can rank Invoice Month (from earliest month) within each Signup Month group, and use the rank number as the column group in Matrix. Please refer to following steps:
- Create a measure for the number of customers.
TotalCustomer = CALCULATE(COUNTROWS('Raw Cohort data')) - Since we will rank the month values, we need to convert the Invoice date into number.
Inv_Year&Month = VALUE ( YEAR ( 'Raw Cohort data'[Invoice_Month] ) & "0" & MONTH ( 'Raw Cohort data'[Invoice_Month] ) ) - Create a column for the rank by Inv_Year&Month within Signup month. You can see the rank in below table chart.
RankInvoiceYear&Month = RANKX ( FILTER ( 'Raw Cohort data', EARLIER ( 'Raw Cohort data'[Signup Month] ) = 'Raw Cohort data'[Signup Month] ), 'Raw Cohort data'[Inv_Year&Month], , ASC, DENSE ) - Drag below data fields into the Matrix chart. Since you already know the DAX for the % view, you can replace “RankInvoiceYear&Month” with the % view DAX and then you can get another % view Matrix.
stfox
10 years agoHelper I
Thanks Simon - Just what I was after. Totally logical - when broken down into those steps
Cheers Steve
BTW - The working example is here - for anyone who requires it in the future
- ThomasDay9 years agoImpactful Individual
What a great thread. Thanks Steve for posting your finished example. Cheers! Tom