Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Consecutives 3 months for unique IDs

Hi experts,

 

I have a question about writing dax formula to find the loyal users who can meet 3 requirement as follows:

1. online bills > 50%,

2. online sales > 50%

3. consecutives 3 months

IDsMonth (in another dim table)Online Bills vs TotalOnline Sales vs TotalConsecutive 3 monthsLoyal user
A01/202240%30%  
A02/202250%70%  
A03/202260%30%xx
B01/202220%40%  
B02/202230%50%  
B04/202270%30%  
B05/202210%70%  
B06/202220%70%xx

 

My question is: 

1. Is it possible to create a sepearate table as above?

2. There is one more table I tried to add, I want to check how long does it take from first order month to the 3rd consecutive month

 

IDsFirst Order Month
A1/2022
B2/2022
C1/2022

 

Would appreciate any ideas. Thanks a lot in advance.

 

  • Hi, Anonymous 

     

    Please check the attachment.

    In this case, 2 consecutive counts are counted for 3 consecutive months. I'm sorry I haven't thought of a better way for the time being, but I can only help you in any way I can.

     

    Best Regards,

    Community Support Team _Charlotte

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

6 Replies

  • daXtreme's avatar
    daXtreme
    Icon for Solution Sage rankSolution Sage

    Sorry but the logic is not clear and the table does not make it any clearer. Please make it more understandable.

  • v-zhangti's avatar
    v-zhangti
    Icon for Community Support rankCommunity Support

    Hi, Anonymous 

     

    You can try the following methods to tell if it is 3 consecutive months.

    Column:

    Next order date =
    MINX (
        FILTER (
            'Dim table',
            [Month] > EARLIER ( 'Dim table'[Month] )
                && [IDs] = EARLIER ( 'Dim table'[IDs] )
        ),
        [Month]
    )
    
    is consecutive? = 
    Var _interval=DATEDIFF([Month],[Next order date],MONTH)
    Return
    IF(_interval=BLANK(),BLANK(),IF(_interval<>1,1,BLANK()))
    Count = 
    Var _count=CALCULATE(COUNT('Dim table'[Month]),FILTER('Dim table',[IDs]=EARLIER('Dim table'[IDs])))
    Var _ids=CALCULATE(MAX('Dim table'[IDs]),FILTER('Dim table',[is consecutive?]=1))
    Var _date1=CALCULATE(MAX('Dim table'[Month]),FILTER('Dim table',[is consecutive?]=1))
    Return
    IF([IDs]=_ids&&[Month]<=_date1,BLANK(),_count)
    Consecutive 3 months =
    CALCULATE (
        COUNT ( 'Dim table'[Month] ),
        FILTER (
            'Dim table',
            [Count] <> BLANK ()
                && [IDs] = EARLIER ( 'Dim table'[IDs] )
                && [Month] <= EARLIER ( 'Dim table'[Month] )
        )
    )
    

    Is this the result you expect?

    Best Regards,

    Community Support Team _Charlotte

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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi v-zhangti , thanks a lot for your support, would you mind explaining the dax that you suggested?

      • v-zhangti's avatar
        v-zhangti
        Icon for Community Support rankCommunity Support

        Hi, Anonymous 

         

        [Next order date] Finds the next order date for each ID in the table. With the DATEDIFF function, you can determine the direct interval between the order date and the next order date. The normal should be 1 month, if not the return is not 1, then consider it not consecutive months.

         

        [is consecutive?] If it is equal to 1, it means that the date less than the corresponding date of this row is not consecutive and needs to start recounting on the next row equal to 1. [Count] is the output of consecutive rows. [Consecutive 3 months] counts consecutive rows over time.

         

        Hope that helps.

         

        Best Regards,

        Community Support Team _Charlotte

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