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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Comparing a sequence number to a date field

I have a table with a sequence order based on the order a supplier sends in shipping notifications and I have a date column based on a receipt date of material. I am trying to see if the receivers are receiving in the correct order based on the supplier's sequence. This example is what I would expect to see, each sequence has a progressively later date. How would I go about writing a query to check for failures?

SEQUENCEDELDATE 
00081/15/2025Are the dates in the order of the sequence?
00091/31/2025 
00102/7/2025 
00112/13/2025 
00122/20/2025 
00132/25/2025 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous,

Thanks for the reply from Greg_Deckler.

 

You could consider creating a measure to check if the dates in the order of the sequence:

DateOrderFailure = 
VAR CurrentSequence = MAX('Table'[SEQUENCE])
VAR CurrentDate = MAX('Table'[DELDATE])
VAR NextSequence = 
    CALCULATE(
        MIN('Table'[SEQUENCE]),
        FILTER(
            'Table',
            'Table'[SEQUENCE] > CurrentSequence
        )
    )
VAR NextDate = 
    CALCULATE(
        MIN('Table'[DELDATE]),
        FILTER(
            'Table',
            'Table'[SEQUENCE] = NextSequence
        )
    )
RETURN 
    IF(
        NOT(ISBLANK(NextDate)) && CurrentDate > NextDate,
        "Failure: Date out of order",
        "Correct order"
    )

vqiaqimsftv_0-1740621651453.png

Then you could apply this measure to a table visual as above.

 

Reards,

Qi

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous,

Thanks for the reply from Greg_Deckler.

 

You could consider creating a measure to check if the dates in the order of the sequence:

DateOrderFailure = 
VAR CurrentSequence = MAX('Table'[SEQUENCE])
VAR CurrentDate = MAX('Table'[DELDATE])
VAR NextSequence = 
    CALCULATE(
        MIN('Table'[SEQUENCE]),
        FILTER(
            'Table',
            'Table'[SEQUENCE] > CurrentSequence
        )
    )
VAR NextDate = 
    CALCULATE(
        MIN('Table'[DELDATE]),
        FILTER(
            'Table',
            'Table'[SEQUENCE] = NextSequence
        )
    )
RETURN 
    IF(
        NOT(ISBLANK(NextDate)) && CurrentDate > NextDate,
        "Failure: Date out of order",
        "Correct order"
    )

vqiaqimsftv_0-1740621651453.png

Then you could apply this measure to a table visual as above.

 

Reards,

Qi

Greg_Deckler
Community Champion
Community Champion

@Anonymous This measure will list any dates that are out of sequence.

Measure = 
    VAR __Table = 
        ADDCOLUMNS(
            ADDCOLUMNS(
                ADDCOLUMNS(
                    'Sequence',
                    "__PrevDate", MAXX( FILTER( ALL( 'Sequence' ), [DELDATE] < EARLIER( [DELDATE] ) ), [DELDATE] )
                ),
                "__PrevID", MAXX( FILTER( ALL( 'Sequence' ), [DELDATE] = [__PrevDate] ), [SEQUENCE] )
            ),
            "__Diff", [SEQUENCE] - [__PrevID]
        )
    VAR __Result = CONCATENATEX( FILTER( __Table, [__Diff] <> 1 && [__PrevDate] <> BLANK() ), [DELDATE], ", " )
RETURN
    __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors