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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Alex215
Frequent Visitor

Determining Previous Status in Table with Same ID

Hi,

 

Need some help to determine the best way to approach the below problem. The table below is a good example of what my raw data looks like. I am trying to create the "Past Status" column below based per "id". If there is no "Past Status" it would just be equal to New like my example below.

 

idFieldOldValueNewValueCreatedDatePast Status
1creatednullnull1/1/2022New
1nameTest1Test21/5/2022New
1statusNewActive1/6/2022New
1DescriptionRandom TextRandom Text1/7/2022Active
1statusActiveArchived1/9/2022Active
1DescriptionRandom TextRandom Text1/12/2022Archived
1statusArchivedActive1/23/2022Archived
1statusActiveArchived1/23/2022Active

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Alex215 ,

 

The value of the date column is not unique, please first create a new index column.

vcgaomsft_1-1649845703694.png

Please create a new calculated column.

Past Status = 
VAR _index =
    CALCULATE (
        MIN ( 'Table'[Index] ),
        FILTER (
            'Table',
            'Table'[Index] >= EARLIER ( 'Table'[Index] )
                && 'Table'[Field] = "status"
                && 'Table'[id] = EARLIER('Table'[id])
        )
    )
VAR _status =
    CALCULATE (
        MAX ( 'Table'[OldValue] ),
        FILTER ( 'Table', 'Table'[Index] = _index )
    )
RETURN
    _status

vcgaomsft_0-1649845514590.png

Attach the PBIX file for reference. Hope it helps.

 

Best Regards,
Community Support Team_Gao

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems with it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Alex215 ,

 

The value of the date column is not unique, please first create a new index column.

vcgaomsft_1-1649845703694.png

Please create a new calculated column.

Past Status = 
VAR _index =
    CALCULATE (
        MIN ( 'Table'[Index] ),
        FILTER (
            'Table',
            'Table'[Index] >= EARLIER ( 'Table'[Index] )
                && 'Table'[Field] = "status"
                && 'Table'[id] = EARLIER('Table'[id])
        )
    )
VAR _status =
    CALCULATE (
        MAX ( 'Table'[OldValue] ),
        FILTER ( 'Table', 'Table'[Index] = _index )
    )
RETURN
    _status

vcgaomsft_0-1649845514590.png

Attach the PBIX file for reference. Hope it helps.

 

Best Regards,
Community Support Team_Gao

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems with it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Hi @Anonymous,

 

Thank you for that information. That worked! I do not use DAX very much so I never even thought to approach the problem that way. 

 

I appreciate all your help!

Anonymous
Not applicable

Hi @Alex215 ,

 

May I ask a question? In the data you posted, are the two lines returned wrong? I'm stuck here.

vcgaomsft_0-1649411047021.png

According to the above rules, should the result they return be Random Text?

 

Best Regards,
Community Support Team_Gao

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems with it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Hi @Anonymous 

 

No sadly. That is why I am also getting stuck at the same point. 

 

The raw data I am getting in are rows of history changes made to a lot of different forms (identified by "id"). I have them sorted by "id" and "CreatedDate" so they appear in the order as shown above. Every change made adds an additional row. The goal of the "Past Status" column is to determine what the Status was when the change was made no matter the type of change which is the "Field" column. 

 

The goal is to calculate what the average duration of time between edits to the same form (identified by "id") while the "Past Status" is equal to New or Active. 

 

idFieldOldValueNewValueCreatedDatePast StatusDuration
1creatednullnull1/1/2022Newnull
1nameTest1Test21/5/2022New4
1statusNewActive1/6/2022New1
1DescriptionRandom TextRandom Text1/7/2022Active1
1statusActiveArchived1/9/2022Active2
1DescriptionRandom TextRandom Text1/12/2022Archived3
1statusArchivedActive1/23/2022Archived11
1statusActiveArchived1/23/2022Active0

 

In this case the average duration for "id"=1 while past status = "New" or "Active" would be 1.6 days ((4+1+1+2+0)/5). I just need help figuring out how to make the "Past Status" column.

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.