Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Matrix Cohort table - date filter issue

Hello Community  -  I have followed this great tutorial (see link) and everything works as expected.  

 

The one "wish" I would like this measure to include is the ability to be controlled (accurately) by a date table.  In the comments of the tutorial the author recognizes that filtering by the Year will yield incorrect results and he recommends to create a disconneted filter table.   I'm trying to avoid that as I will have other visuals on the report page that work just fine with my date table  (connected to sales orders, order date).  

 

Any gurus out there that could figure out how to modify the measure below to make this measurable filterable by the date table and still keep the correct results in the matrix?  

 

Power BI: Cohort Analysis Full Tutorial - Finance BI (finance-bi.com)

New Customers Count =
VAR acquisitionMonth =
    SELECTEDVALUE ( 'Dim_Order Date Table'[Year Month order] )
VAR selectedFutureMonth =
    SELECTEDVALUE ( 'Future months'[Value] )
VAR currentCustomers =
    VALUES ( 'SalesOrdersALL'[Bill To Customer_CustNum] )
VAR pastCustomers =
    CALCULATETABLE (
        VALUES ( SalesOrdersALL[Bill To Customer_CustNum] ),
        ALL ( 'Dim_Order Date Table'[Month & Year], 'Dim_Order Date Table'[MonthnYear] ),
        'Dim_Order Date Table'[Year Month order] < acquisitionMonth
    )
VAR newCustomers =
    EXCEPT ( currentCustomers, pastCustomers )
VAR customersFuturePeriods =
    CALCULATETABLE (
        VALUES ( SalesOrdersALL[Bill To Customer_CustNum] ),
        ALL ( 'Dim_Order Date Table'[Month & Year], 'Dim_Order Date Table'[MonthnYear] ),
        'Dim_Order Date Table'[Year Month order] = acquisitionMonth + selectedFutureMonth
    )
VAR newCustomersBuyingInFuturePeriods =
    INTERSECT ( newCustomers, customersFuturePeriods )

RETURN
     COUNTROWS ( newCustomersBuyingInFuturePeriods )

1 Reply