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
rohanmate
Frequent Visitor

Trying to get Previous Status from Status column to compare with Current Status

Hi Guys,

 

I am trying to create a custom column or measure to show the previous status of the project besides current status,

 

Example:

 

Table Contains:

 

ID       Date      Project Name    Status

 

1     5/10/18         ABC                  G

2     5/11/18         XYZ                  A

3     5/11/18       MNO                 R

4      5/24/18       ABC                  A

5      5/24/18       XYZ                   G

6      5/25/18      MNO                R

 

Output Required:

 

Project Name     Previous Status         Current Status

 

    ABC                        G                                 A

    XYZ                        A                                 G

   MNO                      R                                  R

 

Please help me built measure/ custom column for the previous status column and current status column in such a way that it automatically calculates previous status and current status refreshing the database

 

I tried using this logic where suppose N is current status which calculates the latest date for the project status then, N-1 should try populating its previous record from the table. But I have failed. I would really appreciate if anyone can help me building above calculated columns.

 

Thank you in advance

 

1 ACCEPTED SOLUTION
v-qiuyu-msft
Community Support
Community Support

Hi @rohanmate,

 

You can create a calculated column below: 

 

Previous Status = var t=CALCULATE(MAX('Table1'[ID]),FILTER('Table1','Table1'[ID]<EARLIER(Table1[ID])&& Table1[Project Name]=EARLIER(Table1[Project Name])))
return
LOOKUPVALUE(Table1[Status],Table1[ID],t)

 

q1.PNG

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
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

14 REPLIES 14
Ashish_Mathur
Super User
Super User

Hi,

 

You may refer to my solution in this PBIX file.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi ,

 

Thank you for reverting back, Your screenshot seems kind of excatly What I am trying to achive. But unfortunatly I am unable to open your PBIX file. Can you please resend me our paste the logic.

 

Thank You in advance.

v-qiuyu-msft
Community Support
Community Support

Hi @rohanmate,

 

You can create a calculated column below: 

 

Previous Status = var t=CALCULATE(MAX('Table1'[ID]),FILTER('Table1','Table1'[ID]<EARLIER(Table1[ID])&& Table1[Project Name]=EARLIER(Table1[Project Name])))
return
LOOKUPVALUE(Table1[Status],Table1[ID],t)

 

q1.PNG

 

Best Regards,
Qiuyun Yu 

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

I got the previous Status working by your formula, but I cant see Current status logic or column in the pbix file attached. Please can you help me with getting current status (Where it should give the status by most latest date logged for project name.... Basically it should return only one value)

 

Thank you in advance,

 

Rohan

Hi,

 

My solution gives you the previous and current status.  Did you try that?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi ,

 

I am still not following your directions, Is there any way you could paste the current and previous formula you used in your file and paste it here ?

 

Thanks

Rohan

Hi,

 

Used these measures

 

Most recent date = MAX(Data[Date])

Previous date = CALCULATE(MAX(Data[Date]),DATESBETWEEN(Data[Date],MINX(ALL(Data[Date]),Data[Date]),[Most recent date]-1))

Current Status = LOOKUPVALUE(Data[Status],Data[Date],[Most recent date],Data[Project Name],VALUES(Data[Project Name]))

Previous status = LOOKUPVALUE(Data[Status],Data[Date],[Previous date],Data[Project Name],VALUES(Data[Project Name]))

 

Please also read my previous posts carefully.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi ,

 

I am getting below error "A table of multiple values was supplied where a single value was expected" when creating measure Current Status = LOOKUPVALUE(Data[Status],Data[Date],[Most recent date],Data[Project Name],VALUES(Data[Project Name]))

 

Does this error has to deal with table relationships?

 

Any suggestiuons?


Thank You,

Rohan

Hi,

 

No, nothing to do with relatiosnhips.  Have you done what i suggested on 7/6/2018

 

You have to click on the visual and go to the Roller bruch icon in the Visualisation pane.  Remov the Totals from there.  Now drag the measure in.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

It Also gives me error stating "A table of multiple values was supplied where a single value was expected."

 

Thank You.

Hi @rohanmate,

 

You have to click on the visual and go to the Roller bruch icon in the Visualisation pane.  Remov the Totals from there.  Now drag the measure in.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi v-qiuyu-msft,

Thank you so much for reverting back.

 

I tried applying the same logic in my power BI report but unfortunatly its not taking the data type associated with EARLIER command. Please find below the my logic applied;

 

Where:

 

Project Updates (2) - Table Name

Logged ByID- Id Column

Workstream Name - Project Name Column

OS Label - Status Column

 

PS = var t=CALCULATE(MAX('Project Updates (2)'[Logged ById]),FILTER('Project Updates (2)','Project Updates (2)'[Logged ById]<EARLIER('Project Updates (2)'[Logged ById])&& 'Project Updates (2)'[Workstream Name]=EARLIER('Project Updates (2)'[Workstream Name])))
return
LOOKUPVALUE('Project Updates (2)'[OS Label],'Project Updates (2)'[Logged ById],t)

 

Error Message while creating Custom Column

error message.PNG

Hi @rohanmate,

 

Based on your sample data, my DAX is working. Not sure if your real data is the similar as sample data. Would you please share the pbix file with us? If it does contain sensitive data, please upload report to your OneDrive and send the link to me in private message. 

 

Best Regards,
Qiuyun Yu

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

Hi @v-qiuyu-msft,

 

Can you also please help me with summarizing the total for status.

 

Thank You,

Rohan

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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