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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
DDDDD
Frequent Visitor

How many consecutive days over threshold

I need to identify any row when the Value goes over a set threshold for 3 or more consecutive days.

Example data - each ID is repeated once for each Date. If the Value exceeds 4 over a consecutive 3 day period then I need to mark it somehow.

Sample1.PNG

How do I add a column for this?
Here's the type of output I'm looking for - please advise 🙂

Sample2.PNG

 

 

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Flag = 
VAR __id = DATA[ID]
VAR __pos =
    MAXX(
        FILTER(
            DATA,
            DATA[ID] = __id
                && DATA[Date] <= EARLIER( DATA[Date] )
                && DATA[Value] <= 4
        ),
        DATA[Date]
    )
RETURN
    IF(
        DATA[Date]
            - IF(
                ISBLANK( __pos ),
                MINX( FILTER( DATA, DATA[ID] = __id ), DATA[Date] ) - 1,
                __pos
            ) >= 3,
        "YES"
    )

CNENFRNL_0-1653953651532.png

 

For fun only, to show off the power of Excel worksheet formula,

CNENFRNL_1-1653953739575.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

9 REPLIES 9
DDDDD
Frequent Visitor

Thanks both @VahidDM and @CNENFRNL for your quick responses! Kudos to both 🏆🏆

I've used the verison from @CNENFRNL it seems to work a bit better, or simply more understable to my noob brain.
However, it doesn't seem to handle gaps in the date range, but nvm I've adapted so that there's no gaps by adding any missing dates and zero values.
I've also added modified versions of your solution to show the first date on which the threshold was met so that I can answer questions like "when did it start going over threshold" or "for how long has it been over threshold"

 

Many thanks both :):)

CNENFRNL
Community Champion
Community Champion

Flag = 
VAR __id = DATA[ID]
VAR __pos =
    MAXX(
        FILTER(
            DATA,
            DATA[ID] = __id
                && DATA[Date] <= EARLIER( DATA[Date] )
                && DATA[Value] <= 4
        ),
        DATA[Date]
    )
RETURN
    IF(
        DATA[Date]
            - IF(
                ISBLANK( __pos ),
                MINX( FILTER( DATA, DATA[ID] = __id ), DATA[Date] ) - 1,
                __pos
            ) >= 3,
        "YES"
    )

CNENFRNL_0-1653953651532.png

 

For fun only, to show off the power of Excel worksheet formula,

CNENFRNL_1-1653953739575.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

VahidDM
Super User
Super User

Hi @DDDDD 

 

Try this measure:

Warning = 
Var _CD = MAX('Table'[Date])
Var _CD_1 = _CD-1
Var _CD_2 = _CD-2
Var _A = MAX('Table'[Value])
Var _B = CALCULATE(MAX('Table'[Value]),REMOVEFILTERS('Table'[Date]),'Table'[Date]=_CD_1)
Var _C = CALCULATE(MAX('Table'[Value]),REMOVEFILTERS('Table'[Date]),'Table'[Date]=_CD_2)
return
IF(_A>4&&_B>4&&_C>4,"Yes","No")


Output:

VahidDM_0-1653952565054.png

 

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 FIFA Word Cup Medal Records Dashboard:

https://community.powerbi.com/t5/Charticulator-Design-Challenge/FIFA-World-Cup-Medal-Records/cns-p/2...

CNENFRNL
Community Champion
Community Champion

Interesting method; but what if 30 consecutive days ...


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

@CNENFRNL 

 

That measure will manage 30 consecutive days as well:

VahidDM_0-1653955712422.png


Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 FIFA Word Cup Medal Records Dashboard:
https://community.powerbi.com/t5/Charticulator-Design-Challenge/FIFA-World-Cup-Medal-Records/cns-p/2...

CNENFRNL
Community Champion
Community Champion

I mean, flag the column after 30 consecutive records of a streak; take your own mockup for instance, from 2022/5/30 and onwards.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Not sure I got your point correctly or not, but FYI:

VahidDM_0-1653957314726.png


Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

CNENFRNL
Community Champion
Community Champion

Hmm... start marking "yes" from 5/30.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Yes, because 1-Jun-22 is still in 3 days consecutive period.

 


Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.