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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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

@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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.