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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Bertenvanloover
Frequent Visitor

Find Text from List in Rows with same ID as current row

Hi, I could use some help finding a way to do the manipulation below in Power Query:
I want to create a custom column "Already_Approved" that shows
* "Yes" when chronologically² the last row in the same table with the same Document_ID has a transaction field that contains "Approving Done" or "Approved"
* and "No" when this chronologically last row does not have that Transaction.

Purpose: this table shows a history log of changes to the status of Documents, where each Document has a unique Document_ID. And I'd like to create a list of all non-approved Documents that are "Send for Approval" or "Send back for Editing". So after this step I will filter out only the "Send for Approval" and "Send back for editing" with "Already_Approved" = "No".

²Staying away from "chronologically" might create more robust results, though I don't want to overcomplicate my question 🙂 Cause for example "Document_ID=3" was send back after a mistake was found later on.

Document_IDTransactionDateAlready_Approved
1Created22/02/2023 11:00Yes
1Send for Approval22/02/2023 11:01Yes
1Approving Done22/02/2023 11:02Yes
2Created22/02/2023 11:05No
2Send for Approval22/02/2023 11:06No
3Created22/02/2023 11:00No
3Send for Approval22/02/2023 11:02No
3Send back for Editing22/02/2023 11:03No
3Send for Approval22/02/2023 11:05No
3Approved22/02/2023 11:10No
3Change Editing Required11/09/2023 09:11No

 

This is only my second Power Query to date, so I'm a complete rookie. Thanks for the help!

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

NewStep=let a=Table.Group(PreviousStepName,"Document_ID",{"n",each Table.Sort(_,{"Date",1}){0}[Transaction]}) in Table.AddColumn(PreviousStepName,"Already_Approved",each if a{[Document_ID=[Document_ID]]}[n]="Approved" then "Yes" else "No")

View solution in original post

2 REPLIES 2
Bertenvanloover
Frequent Visitor

Awesome Daniel! It made me swing my arms in the air for a winning gesture 😄
You made my day, I wish you an amazing weekend in return 😉

wdx223_Daniel
Super User
Super User

NewStep=let a=Table.Group(PreviousStepName,"Document_ID",{"n",each Table.Sort(_,{"Date",1}){0}[Transaction]}) in Table.AddColumn(PreviousStepName,"Already_Approved",each if a{[Document_ID=[Document_ID]]}[n]="Approved" then "Yes" else "No")

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.