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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

Returning max value of table if row is in list of another table

Hey guys I have two tables, one Dimension table and one fact table

Fact

ID

ListOfStrings

MaxIndex

1

{ mouse, elephant }

3

Dim

Index

Description

1

mouse

2

tiger

3

elephant

My goal is to to write an expression which is able to check the dimensiontable for all Strings in ListStrings and return the maxIndex

I already had alot of different expression, my current one is:

 

 

 

= Table.AddColumn(Source, "MaxIndex", each

List.Max(

List.Select(

Table.SelectRows(#"Dim",

each List.Contains([ListOfStrings],[Description]))[Index],

each _ <> null))

)

 

 

 

but I get this error:Expression.Error: The field 'ID' of the record wasn't found.

It seems like an easy problem but I sadly cant figure it out. Any help is appreciated.


Edit:

It seems like I cant pass the column directly or any other parameter of the table I'm currently working in. Is there a way to declare a variable before I use the first List. method? Or can I access the first "each" somehow?

 

Edit2:

Made it work by extracting the logic into a function 

mFunction =
(list) => List.Max(

List.Select(

Table.SelectRows(#"Dim",

each List.Contains(list,[Description]))[Index],

each _ <> null))
= Table.AddColumn(Source, "MaxIndex", each myFunction([listOfStrings])

 

 

tyvm

2 REPLIES 2
wdx223_Daniel
Super User
Super User

=let a=Table.Buffer(Table.Sort(Dim,{"Index",1})) in Table.AddColumn(Fact,"MaxIndex",each Table.Skip(a,(x)=>not List.Contains([ListOfStrings],x[Description])){0}?[Index]?)

Anonymous
Not applicable

Thank you for our solution. Unfortunatly your solution as well as mine takes way to long to evaluate and reads to much data. I stopped on 156MB, the facttables original size is only 3MB.

pdhlk_0-1662021104080.png

 

My Stringlist might be the problem because its a function aswell. Well I stopped PBI from reading all the data by bufering the fact table also but it still takes way to long to evaluate. Do you have a hint why this has such a bad performance?

StringListFunction = 
(buffered_table,ID) => 
List.Distinct(
List.Select(
Table.SelectRows(buffered_table, each [ID]=ID)[Description],
each _ <> null
))

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors