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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Naveen112
Regular Visitor

Previous row value to a New column

Hi All,

 

Can you please help me the below Output for the Previous_State Column : I need to have the previous value of  each state  to derive the "State time in days" So that it will be useful for the management to check how many days a ticket has been pending in each state to track the users.
Please note that State Column has duplicate states as there is a DATE column with current snap shot of dates till date. Sample Dat below a is the exact sample of what I have in database. As I am using STATE CHANGE DATE column for my calculation and not using the DATE column in any of my calculations I havent included this column in the below sample data.
Tried with the below code but not working:

Previous_State=
CALCULATE (
     MAX('table'[State]) ,
        ALLEXCEPT ( 'table', 'table'[Work Item Id] ),
        'table'[State] < EARLIER('table'[State])  
)



Workitem IDState State change DatePrevious_StateState Time In Days
1001backlog4/1/2024  
1001backlog4/1/2024  
1001backlog4/1/2024  
1001backlog4/1/2024  
1001Inprogress15/1/2024backlog11
1001Inprogress15/1/2024backlog11
1001Inprogress15/1/2024backlog11
1001Done20/1/2024Inprogress5
1001Done20/1/2024Inprogress5
1001Done20/1/2024Inprogress5
1001Done20/1/2024Inprogress5
2001backlog5/1/2024  
2001backlog5/1/2024  
2001backlog5/1/2024  
2001Inprogress13/1/2024backlog8
2001Inprogress13/1/2024backlog8
2001Inprogress13/1/2024backlog8
2001Done18/1/2024Inprogress5
2001Done18/1/2024Inprogress5
2001Done18/1/2024Inprogress5

 

Thanks,

 

 

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

@Naveen112 

You need to look at the date, rather than the state, like this.

Previous State = 
VAR _PrevDate =
    CALCULATE (
        MAX ( 'Table'[State change Date] ),
        ALLEXCEPT ( 'Table', 'Table'[Workitem ID] ),
        'Table'[State change Date] < EARLIER ( 'Table'[State change Date] )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[State] ),
        ALLEXCEPT ( 'Table', 'Table'[Workitem ID] ),
        'Table'[State change Date] = _PrevDate
    )

Then the Days in state is like this.

State Time In Days = 
VAR _PrevDate =
    CALCULATE (
        MAX ( 'Table'[State change Date] ),
        ALLEXCEPT ( 'Table', 'Table'[Workitem ID] ),
        'Table'[State change Date] < EARLIER ( 'Table'[State change Date] )
    )
RETURN
    IF ( ISBLANK ( _PrevDate ), BLANK (), INT ( [State change Date] - _PrevDate ) )

jdbuchanan71_0-1716184115077.png

 

View solution in original post

2 REPLIES 2
ThxAlot
Super User
Super User

ThxAlot_0-1716184627897.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



jdbuchanan71
Super User
Super User

@Naveen112 

You need to look at the date, rather than the state, like this.

Previous State = 
VAR _PrevDate =
    CALCULATE (
        MAX ( 'Table'[State change Date] ),
        ALLEXCEPT ( 'Table', 'Table'[Workitem ID] ),
        'Table'[State change Date] < EARLIER ( 'Table'[State change Date] )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[State] ),
        ALLEXCEPT ( 'Table', 'Table'[Workitem ID] ),
        'Table'[State change Date] = _PrevDate
    )

Then the Days in state is like this.

State Time In Days = 
VAR _PrevDate =
    CALCULATE (
        MAX ( 'Table'[State change Date] ),
        ALLEXCEPT ( 'Table', 'Table'[Workitem ID] ),
        'Table'[State change Date] < EARLIER ( 'Table'[State change Date] )
    )
RETURN
    IF ( ISBLANK ( _PrevDate ), BLANK (), INT ( [State change Date] - _PrevDate ) )

jdbuchanan71_0-1716184115077.png

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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