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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

List.Transform Error when using List.Contains or List.ContainsAny but not when using OR comparison.

Hello,

I am working on some transformation, and I have found out behavior of PQ that I dont understand.

 

When I am using the code:

 

= List.Transform( Custom3{0}[Record], each if _ = "2024" or _ = "2023" or _ = "2022" or _ = "2021"or _ = "2020"   then null else _ )

 

all is working as I want.

Now I wished to clean the code a bit so instead of listing the years 1 by 1 I decided to use List.Contains and List.Contains.Any
In it I decided to use numerical text {"2020".."2030"} and this gave me the error

RadoslawPop_0-1725978063956.png

the issue / question is how do I generate a range from 2020 to 2030 as text values.
also why cant I genare sequence of "2020" to "2030" ?

3 REPLIES 3
Anonymous
Not applicable

Hello,
Thank you all for answering,
Thank you for the methods presented and I was already aware of them.
I was hoping there is more direct way of doing this.
anmd that I am missing some basic detail on how to do it.
Thank you again

Omid_Motamedise
Super User
Super User

you can use this formula instead
=each  List.Contains({"2022","2023","2024","2025","2026"}, _ )


If my answer helped solve your issue, please consider marking it as the accepted solution.
lbendlin
Super User
Super User

The  ..  notation only works with integers or with single characters. For example {"A".."Z"}  works but {"AA".."ZZ"} doesn't.

 

Create a numeric list {2020..2030}  and then use Text.From(_)

 

= List.Generate(()=> 2020, each _ < 2031 , each _ +1, each Text.From(_))

 

or

 

= List.Transform({2020..2030},each Text.From(_))

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors