Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Filter context not working as expected

Hi all, I have a table with customers IDs, and their first, second and third car purchase dates. With the below formula, what I am trying to do is at any given date, calculate the number of customers...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous ,

    Please have a try.

    Two_cars_customers_count =
    VAR tmpEff =
        ADDCOLUMNS (
            'Device PURCHASE data',
            "Effective Date", IF ( ISBLANK ( [THIRD_PURCHASE_DATE] ), TODAY (), [THIRD_PURCHASE_DATE] )
        )
    VAR tmpTable =
        SELECTCOLUMNS (
            FILTER (
                GENERATE ( tmpEff, 'Date_Lookup' ),
                [Date] >= [SECOND_PURCHASE_DATE]
                    && [Date] < [Effective Date]
                    && [SECOND_PURCHASE_DATE] <> BLANK ()
            ),
            "ID", [Customer_ID],
            "Date", [Date]
        )
    VAR tmpTable1 =
        GROUPBY (
            ALLEXCEPT ( tmpTable, tmpTable[ID] ),
            tmpTable[ID],
            "Count", COUNTX ( CURRENTGROUP (), [Date] )
        )
    RETURN
        IF ( ISBLANK ( COUNTROWS ( tmpTable1 ) ), 0, COUNTROWS ( tmpTable1 ) )
    

     

    How to Get Your Question Answered Quickly 

     

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

     

    Best Regards
    Community Support Team _ Rongtie

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.