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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors