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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
TL_675789
New Member

Need help creating a calculated column to return the previous row's text value

Hi,

 

I have a data set which contains orders and all of the statuses within an order are ranked. I have an existing calculated column that has the status name with a # appended to the end to represent the instance of that specific status. I would like to create a new column that simply pulls the previous status from this column. Below is a sample of how the data is structured and the last column is the one I am trying to create. 

 

Order #SequenceTask StatusCalculated Column
546781Approved1null
546782Repair1Approved1
546783QC1Repair1
546784Approved2QC1
789011Repair1null
789012Audit1Repair1
789013Delivered1Audit1
1 ACCEPTED SOLUTION

Hi @TL_675789 

 

I'd like to suggest you using measure rather than calculated column:

Measure 5 = var a = MAX(Sheet[Sequence])-1
var b = CALCULATE(MAX(Sheet[Task Status]),FILTER(ALL(Sheet),[Sequence]=a),VALUES(Sheet[Order #]))
Return b

001.PNG 

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

4 REPLIES 4
amitchandak
Super User
Super User

User earlier

 

https://community.powerbi.com/t5/Desktop/Explanation-of-the-EARLIER-formula/td-p/529469

https://community.powerbi.com/t5/Desktop/FILTER-EARLIER-expression-just-how-is-it-working/td-p/24682...

https://docs.microsoft.com/en-us/dax/earlier-function-dax

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.

My Recent Blog - https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak  I have tried a few versions of the earlier function and just can't get the values that I am expecting. I tried the DAX code below and it just returns the same value as the current row.

 

 

Calculated Column = 
VAR CurrentRow = Table[sequence]
VAR CurrentStatus = Table[status]
VAR PreviousDate =
    CALCULATE (
        MAX ( Table[sequence] ),
        FILTER ( ALL ( Table ), Table[sequence] < CurrentRow && Table[status] = CurrentStatus)
    )
RETURN
    CALCULATE (
        SELECTEDVALUE( Table[status] ),
        FILTER ( ALL ( Retail_Inventory_Revenue_Tasks ), Table[sequence] = PreviousDate && Table[status] = CurrentStatus)
    )

 

I figured it would be some instance of the earlier function, but I just can't get it to work. Any suggestion on how I would use it in this specific example? 

 

I tried the code below, but it just returns the same value. 

 

calculated column = calculate(min([Task Status]),[Sequence]=earlier[Sequence])

Hi @TL_675789 

 

I'd like to suggest you using measure rather than calculated column:

Measure 5 = var a = MAX(Sheet[Sequence])-1
var b = CALCULATE(MAX(Sheet[Task Status]),FILTER(ALL(Sheet),[Sequence]=a),VALUES(Sheet[Order #]))
Return b

001.PNG 

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

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.