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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Calculate previous status when data is updated multipe times a month

Hello,

 

I have a Dataset called "Pipeline" and key column called "Project ID" , a column called "Status" and a column called "Date Update".

 

Project IDStatusDate Updated
11Pending02/09/2020
12Pending02/09/2020
13Approved02/09/2020
14Pending02/09/2020
12Pending08/09/2020
14Approved08/09/2020
12Approved15/09/2020
14Running15/09/2020
15Pending15/09/2020
16Pending15/09/2020

 

I would like to add a new column called, "Previous Status" that looks at the status of a project in the previous time period and add it next to the current status. It should be something like this:

 

Project IDStatusDate UpdatedPrevious Status
11Pending02/09/2020No record
12Pending02/09/2020No record
13Approved02/09/2020No record
14Pending02/09/2020No record
12Pending08/09/2020Pending
14Approved08/09/2020Pending
12Approved15/09/2020Pending
14Running15/09/2020Approved
15Pending15/09/2020No record
16Pending15/09/2020No record

 

Please note that the date when the dates when the dataset is updated are quite random. 

 

I did this before for the situation when the dataset was updated Monthly, but that does not work anymore with the dataset being updated at random dates. Please see the previous code below:

 

PreviousStatus = IF(ISBLANK(MAXX(FILTER(Pipeline,Pipeline[ID]=EARLIER(Pipeline[ID])&&EOMONTH(Pipeline[Date Updated],0) = EOMONTH(EARLIER(Pipeline[Date UPDATED]),-1)),Pipeline[Status]))=FALSE,MAXX(FILTER(Pipeline,Pipeline[ID]=EARLIER(Pipeline[ID])&&EOMONTH(Pipeline[Date UPDATED],0) = EOMONTH(EARLIER(Pipeline[Date UPDATED]),-1)),Pipeline[Status]),"No record").
 
Thank you!
1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Try to create a calculated column like so:

Previous Status =
VAR PreviousMaxDate =
    CALCULATE (
        MAX ( Pipeline[Date Updated] ),
        FILTER (
            Pipeline,
            Pipeline[Project ID] = EARLIER ( Pipeline[Project ID] )
                && Pipeline[Date Updated] < EARLIER ( Pipeline[Date Updated] )
        )
    )
VAR PreviousStatus =
    CALCULATE (
        MAX ( Pipeline[Status] ),
        FILTER (
            Pipeline,
            Pipeline[Project ID] = EARLIER ( Pipeline[Project ID] )
                && Pipeline[Date Updated] = PreviousMaxDate
        )
    )
RETURN
    IF ( ISBLANK ( PreviousStatus ), "No record", PreviousStatus )

pre.PNG

 

 

Best Regards,

Icey

 

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
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Try to create a calculated column like so:

Previous Status =
VAR PreviousMaxDate =
    CALCULATE (
        MAX ( Pipeline[Date Updated] ),
        FILTER (
            Pipeline,
            Pipeline[Project ID] = EARLIER ( Pipeline[Project ID] )
                && Pipeline[Date Updated] < EARLIER ( Pipeline[Date Updated] )
        )
    )
VAR PreviousStatus =
    CALCULATE (
        MAX ( Pipeline[Status] ),
        FILTER (
            Pipeline,
            Pipeline[Project ID] = EARLIER ( Pipeline[Project ID] )
                && Pipeline[Date Updated] = PreviousMaxDate
        )
    )
RETURN
    IF ( ISBLANK ( PreviousStatus ), "No record", PreviousStatus )

pre.PNG

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Worked as magic! Thanks!

Nicolas_Sylla
Frequent Visitor

Hi Maybe you can create a virtual table like this :

Pipeline4Report =
SELECTCOLUMNS(Pipeline,
"Project",Pipeline[Project],
"Status", Pipeline[Status],
"Updated", Pipeline[Date Updated],
"Previous State",
VAR CurrentProj = Pipeline[Project]
VAR CurrentDte = Pipeline[Date Updated]
VAR PrevDte= CALCULATE(MAX(Pipeline[Date Updated]),Filter(Pipeline,Pipeline[Project]=CurrentProj && Pipeline[Date Updated]<CurrentDte))
VAR PrevState =CALCULATE(LASTNONBLANK(Pipeline[Status],1),Filter(all(Pipeline),Pipeline[Project]=CurrentProj && Pipeline[Date Updated]=PrevDte))
RETURN
IF(ISBLANK(PrevState),"No Record",PrevState)
)
 
Did I answer your question? Mark my post as a solution!
 
2020-09-16_16h11_38.png

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.