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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

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.

 

1 ACCEPTED SOLUTION

Hi, @Anonymous 

 

Please check the attachment.

vzhangti_1-1668760999561.png

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.

View solution in original post

6 REPLIES 6
v-zhangti
Community Support
Community 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] )
    )
)

vzhangti_0-1668580925276.png

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
Not applicable

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

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.

Anonymous
Not applicable

Hi Charlotte,

I got your point! However, when I check the data, even though the store did not buy consecutive but it still counts 7 as the picture below

 

anhdoox_0-1668682414472.png

Could you please help me how to fix it?

Hi, @Anonymous 

 

Please check the attachment.

vzhangti_1-1668760999561.png

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.

daXtreme
Solution Sage
Solution Sage

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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