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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ftmanoel
Frequent Visitor

Power query - create new column with first occurrence of each group

Hi everyone,

 

I'm trying to achieve something in power query and I'm struggling. I have done this with DAX but with power query I am clearly missing something.

 

I have a status evolution table such as the one in the imagem below, where each line has a unique ID, a group ID, the old and new status and the transition date. What I need is to create a new column where the first transition to status4 for each group  is the value in this new column. I tried to show an example in the image below.

ftmanoel_0-1685547348825.png

I attempted to do this with the following logic but I was unsuccessful: 

 

 

 

= Table.AddColumn(
#"Colunas Removidas1", "newColumn", 
each let 
groupId = [groupId],
minHistId = List.Min(Table.SelectRows(#"Colunas Removidas1",
each 
[groupId] = groupId 
and [transitionDate] = Date.From(DateTime.Date([transitionDate]))) [uniqueId]),
transitionDate = 
if [newStatus] = "STATUS4" 
then 
Date.From(DateTime.Date(List.Min(Table.SelectRows(#"Colunas Removidas1",
each [groupId] = groupId 
and [uniqueId] = minHistId 
and [transitionDate] = Date.From(DateTime.Date(List.Min(Table.SelectRows(#"Colunas Removidas1", each [groupId] = groupId and [newStatus] = "STATUS4")[transitionDate])))))[transitionDate]))
else null in transitionDate)

 

 

 

This correctly selects the rows where the first transition is present since all other values are null, but the rows where the calculated value was supposed to be have the following error: "Expression.Error: Cannot convert a value of type Table to type List."

ftmanoel_2-1685547707969.png

 

 

Thank you in advance.

1 REPLY 1
wdx223_Daniel
Super User
Super User

=let a=Table.Group(#"Colunas Removidas1","GroupId",{"n",each Table.Skip(_,each [newStatus]<>"STATUS4"){0}?[transitionDate]?}) in Table.AddColumn(#"Colunas Removidas1","newColumn",each a{[GroupId=[GroupId]]}?[n]?)

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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