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

Compare Row to Same Column While Filtering on Date

Hello, I am trying to create a calculated column to track day-to-day changes to claims. The highlighted Change column is the objective. I want to compare the Claim # to only the prior working day report to track the changes. I provided a simplified version of the data below. The Change column for 4/22/20 can be blank because it is the starting point thus no prior report to compare.

  • if Claim # does not match any of the prior report date Claim # then return "New" (Example: Row 7, 12, 13)
  • if Claim # match the previous report date Claim # AND:
    • Status = prior Status AND Last Saved Date < prior Report Date then return "No Change" (Example: Row 6, 8 )
    • Status = prior Status AND Last Saved Date >= prior Report Date then return "Updated" (Example: Row 9, 11)
    • Else return current report date's status (Example: Row 5, 10)

 

Example.PNG

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

hi  @Anonymous 

You could use this logic to get it:

Change = 
var _firstdate=CALCULATE(MIN('Table'[Report Date]),ALL('Table'))
var _perdate=CALCULATE(MAX('Table'[Report Date]),FILTER('Table','Table'[Report Date]<EARLIER('Table'[Report Date]))) 
var _perclaimstatus=CALCULATE(MAX('Table'[Status]),FILTER('Table','Table'[Report Date]=_perdate&&'Table'[Claim #]=EARLIER('Table'[Claim #])))
return
IF (
        _firstdate = 'Table'[Report Date],
        BLANK (),
        IF (
            CALCULATE (
                MAX ( 'Table'[Claim #] ),
                FILTER (
                    'Table',
                    'Table'[Report Date] = _perdate
                        && 'Table'[Claim #] = EARLIER ( 'Table'[Claim #] )
                )
            )
                = BLANK (),
            "New",
            IF (
                'Table'[Last Saved Date] = BLANK ()
                    && _perclaimstatus <> 'Table'[Status],
                'Table'[Status],
                IF (
                    _perclaimstatus = 'Table'[Status]
                        && 'Table'[Last Saved Date] < _perdate,
                    "No Change",
                    IF (
                        _perclaimstatus = 'Table'[Status]
                            && 'Table'[Last Saved Date] >= _perdate,
                        "Updated"
                    )
                )
            )
        )
    )

Result:

1.JPG

 

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
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

3 REPLIES 3
v-lili6-msft
Community Support
Community Support

hi  @Anonymous 

You could use this logic to get it:

Change = 
var _firstdate=CALCULATE(MIN('Table'[Report Date]),ALL('Table'))
var _perdate=CALCULATE(MAX('Table'[Report Date]),FILTER('Table','Table'[Report Date]<EARLIER('Table'[Report Date]))) 
var _perclaimstatus=CALCULATE(MAX('Table'[Status]),FILTER('Table','Table'[Report Date]=_perdate&&'Table'[Claim #]=EARLIER('Table'[Claim #])))
return
IF (
        _firstdate = 'Table'[Report Date],
        BLANK (),
        IF (
            CALCULATE (
                MAX ( 'Table'[Claim #] ),
                FILTER (
                    'Table',
                    'Table'[Report Date] = _perdate
                        && 'Table'[Claim #] = EARLIER ( 'Table'[Claim #] )
                )
            )
                = BLANK (),
            "New",
            IF (
                'Table'[Last Saved Date] = BLANK ()
                    && _perclaimstatus <> 'Table'[Status],
                'Table'[Status],
                IF (
                    _perclaimstatus = 'Table'[Status]
                        && 'Table'[Last Saved Date] < _perdate,
                    "No Change",
                    IF (
                        _perclaimstatus = 'Table'[Status]
                            && 'Table'[Last Saved Date] >= _perdate,
                        "Updated"
                    )
                )
            )
        )
    )

Result:

1.JPG

 

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thank you! I made some minor edits and it works as I intended.

Greg_Deckler
Community Champion
Community Champion

See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...



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