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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
chart
Frequent Visitor

Return text value from a previous row that contains the same value in another column

For each Ticket, I want the priorowner column to show who the Owner was in the same ticket's previous modification row. For example, for ticket 128009, the first priorowner cell would be blank because there was no previous Owner. The next 2 rows for 128009 would show Level 2 Team, then Jane Doe, then Peter Parker, etc. I filled in the values below in priorowner for ticket 128009 that I would want to see. I created an index row so that I could order the modifications for each ticket and I know I need to filter somehow to return values for each unique ticket, but I am stuck!

 

I spent ages getting to this point, but realized that calculate max is only for numerical values, not text: 

priorowner = IF( 'Table1'[diff row] <> 0, CALCULATE(Max(Table1[Owner]),FILTER(Table1,Table1[TicketCalc] =EARLIER(Table1[TicketCalc])&&Table1[Index]<EARLIER(Table1[Index]))))

 

Please help!

 

Here is a section of my dataset:

 

modifiedonTicketIndexOwnerpriorowner
2/16/2022 10:381280099269Level 2 Team 
2/15/2022 18:431279849230Level 2 Team 
2/16/2022 8:431279849244Level 2 Team 
2/16/2022 18:351280099422Level 2 TeamLevel 2 Team
2/16/2022 8:421279849243Jane Doe 
2/16/2022 16:021280099384Jane DoeLevel 2 Team
2/15/2022 19:041279849231John Doe 
2/16/2022 9:201279849250John Doe 
2/16/2022 18:371280099423Peter ParkerJane Doe
2/15/2022 19:051279849232Level 3 Team 
2/16/2022 10:491280099273Level 3 TeamPeter Parker
2/8/2022 13:071272198498Level 3 Team 
2/8/2022 13:481272198516Bruce Banner 
2/8/2022 17:041272198563Tony Stark 
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Here is a Power Query version:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hZHNasMwEIRfRegcyGq1+j2GnEIPgeYWfDBlodBWBpME8va1XDtBitOcVof5NDO7x6PEtbJrBEShIGovV1KhBwjDI6DN440v/C1QHLj9kc1qRMyE+Eh6RFzwNCIaniCTyyNB9D8xmGhT5CLElyZYmWTTXZtYbDuuDWwELAz0SNXyuXSIQFVpleXdZ1r4PUSEUm3guTqXdVXZHH3PJ+7Fvu2/uF/IY6o89/3oxZVCpFCe2ullxE+EjvCXy6HKhKfgXxHkC8IoO4xNf/5gsWlTujWZCXdb7EzYnOrQpat4Pw3dZdP8Ag==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [modifiedon = _t, Ticket = _t, Index = _t, Owner = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"modifiedon", type datetime},  {"Index", Int64.Type}, {"Owner", type text}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Index", Order.Descending}}),
    #"Added Custom" = Table.AddColumn(#"Sorted Rows", "PriorOwner", each try Table.SelectRows(#"Sorted Rows",(k)=> k[Ticket]=[Ticket] and k[Index]<[Index]){0}[Owner] otherwise null)
in
    #"Added Custom"

and here is the same in a DAX calculated column:

Prior Owner = 
var i = 'Table'[Index]
var pi = CALCULATE(max('Table'[Index]),ALLEXCEPT('Table','Table'[Ticket]),'Table'[Index]<i)
return CALCULATE(max('Table'[Owner]),ALLEXCEPT('Table','Table'[Ticket]),'Table'[Index]=pi)

 

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

Here is a Power Query version:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hZHNasMwEIRfRegcyGq1+j2GnEIPgeYWfDBlodBWBpME8va1XDtBitOcVof5NDO7x6PEtbJrBEShIGovV1KhBwjDI6DN440v/C1QHLj9kc1qRMyE+Eh6RFzwNCIaniCTyyNB9D8xmGhT5CLElyZYmWTTXZtYbDuuDWwELAz0SNXyuXSIQFVpleXdZ1r4PUSEUm3guTqXdVXZHH3PJ+7Fvu2/uF/IY6o89/3oxZVCpFCe2ullxE+EjvCXy6HKhKfgXxHkC8IoO4xNf/5gsWlTujWZCXdb7EzYnOrQpat4Pw3dZdP8Ag==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [modifiedon = _t, Ticket = _t, Index = _t, Owner = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"modifiedon", type datetime},  {"Index", Int64.Type}, {"Owner", type text}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Index", Order.Descending}}),
    #"Added Custom" = Table.AddColumn(#"Sorted Rows", "PriorOwner", each try Table.SelectRows(#"Sorted Rows",(k)=> k[Ticket]=[Ticket] and k[Index]<[Index]){0}[Owner] otherwise null)
in
    #"Added Custom"

and here is the same in a DAX calculated column:

Prior Owner = 
var i = 'Table'[Index]
var pi = CALCULATE(max('Table'[Index]),ALLEXCEPT('Table','Table'[Ticket]),'Table'[Index]<i)
return CALCULATE(max('Table'[Owner]),ALLEXCEPT('Table','Table'[Ticket]),'Table'[Index]=pi)

 

Thank you so much! That worked perfectly!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.