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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
helen_brunyee95
Frequent Visitor

Consecutive monthly instances of a value

Hi everyone,

 

I have been wracking my brains and pretty much tried every option out there on forumns etc. for this, but I'm not getting anywhere fast - so any help will me HUGELY appreciated!

 

Essentially, I have been tasked with getting a list of Sites ("C_L_code" ) which have, at any point in the last year, had 3 consecutive months (or more) of no visits. 

 

Here is my table. It shows the list of sites, for every month, with total visits:

helen_brunyee95_0-1752740963646.png

 

 

I have added a VisitsFlag (in PowerQuery) which is simply just:

 

each if [Visits] = null then 0 else 1)

 

I also have a MonthIndex column, which I added at one point during one of mym any failed attempts at a solution, but left it in, in case it's useful:

MonthIndex =

RANKX(

    FILTER(D_AllSitesMonth, D_AllSitesMonth[C_L_code] = EARLIER(D_AllSitesMonth[C_L_code])),

    D_AllSitesMonth[MonthStart],

    ,

    ASC,

    DENSE

)

 

 

Any ideas how I would achieve this? Basically need a way of knowing if VisitedFlag for a site is 0 for 3 months or more, in a row, at any point.

I'm at a loss as to where to go with it now...maybe I'm just missing something obvious?

 

Thanks in advance!

1 ACCEPTED SOLUTION
harnoorsekhon
Regular Visitor

Hi @helen_brunyee95 
You create a calculated column as follows:

ConsecNoVisitStreak =
VAR CurrentSite = [C_L_code]
VAR CurrentMonth = [MonthIndex]
VAR Prev2 = CALCULATE(
    MIN(D_AllSitesMonth[VisitsFlag]),
    FILTER(
        D_AllSitesMonth,
        D_AllSitesMonth[C_L_code]=CurrentSite &&
        D_AllSitesMonth[MonthIndex]=CurrentMonth-1
    )
)
VAR Prev3 = CALCULATE(
    MIN(D_AllSitesMonth[VisitsFlag]),
    FILTER(
        D_AllSitesMonth,
        D_AllSitesMonth[C_L_code]=CurrentSite &&
        D_AllSitesMonth[MonthIndex]=CurrentMonth-2
    )
)
RETURN IF(
    [VisitsFlag]=0 && Prev2=0 && Prev3=0, 1, 0
)


You can then filter the table for rows where ConsecNoVisitStreak=1 and retrieve those C_L_code

Hope this solution helps you make the most of Power BI! If it did, click 'Mark as Solution' to help others find the right answers.
Show some love with kudos 👍 as your support keeps our community thriving!
 

View solution in original post

2 REPLIES 2
harnoorsekhon
Regular Visitor

Hi @helen_brunyee95 
You create a calculated column as follows:

ConsecNoVisitStreak =
VAR CurrentSite = [C_L_code]
VAR CurrentMonth = [MonthIndex]
VAR Prev2 = CALCULATE(
    MIN(D_AllSitesMonth[VisitsFlag]),
    FILTER(
        D_AllSitesMonth,
        D_AllSitesMonth[C_L_code]=CurrentSite &&
        D_AllSitesMonth[MonthIndex]=CurrentMonth-1
    )
)
VAR Prev3 = CALCULATE(
    MIN(D_AllSitesMonth[VisitsFlag]),
    FILTER(
        D_AllSitesMonth,
        D_AllSitesMonth[C_L_code]=CurrentSite &&
        D_AllSitesMonth[MonthIndex]=CurrentMonth-2
    )
)
RETURN IF(
    [VisitsFlag]=0 && Prev2=0 && Prev3=0, 1, 0
)


You can then filter the table for rows where ConsecNoVisitStreak=1 and retrieve those C_L_code

Hope this solution helps you make the most of Power BI! If it did, click 'Mark as Solution' to help others find the right answers.
Show some love with kudos 👍 as your support keeps our community thriving!
 

Hi @harnoorsekhon !

Thank you so much for getting back to me (so quickly!) and for this fab solution! This will work perfectly. I cannot tell you how much of a headache you have saved me - this is genius!! Really appreciate it 🙂

 

Thanks again!! 

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.

Top Solution Authors