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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

List.Select - Power Query M Language

Hi community!

I'm trying to return values from a column ([ListColumn]) which contains a comma separated list, using M code. The particular entries I want to return are ended with a colon. For example, the (text) list might look like this: "Command:, process, management, Leadership:, process". I want to return "Command:, Leadership:"

 

I have tried the following code, but just get an error:

AddColumn = Table.AddColumn(PreviousStep, "New Column", each List.Select([ListColumn], Text.End(_ ,1)=":" )) 

 

Any pointers? I'm new to using list functions.

 

Regards

Will

8 REPLIES 8
pqian
Microsoft Employee
Microsoft Employee

 @Anonymous you are missing the "each" in the condition

 

AddColumn = Table.AddColumn(PreviousStep, "New Column", each List.Select([ListColumn], each Text.End(_ ,1)=":" )) 
Anonymous
Not applicable

Sorry, that was an omission.

 

Even with the code you suggest, I get a column full of "Error". Is it something to do with the [ListColumn]? The entries in it are literally like this: 

 

Weather:, Weather, Conditions:, Arrangement/Placement of items

 

Will they be recognised as a list because of the commas, or do I need to do something to process them a bit first?

 

Many thanks,

Will

Anonymous
Not applicable

I have also tried retrieving the positions of the various text strings (which end in colons) using the following:

 

ListPositions = Table.AddColumn(PreviousStep, "New Column", each List.PositionOfAny([ListColumn], {"Command:","Management decision:"}, Occurrence.All))

 

...but this also leads to a column of "Error", unfortunately.

 

Will

 

 

ImkeF
Community Champion
Community Champion

What does the error say?

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Hi Imke,

It says...

 

Expression.Error: We cannot convert the value "Command:, processes" to type List.
Details:
Value=Command:, processes
Type=Type

 

My column is just a text string, but I don't know how to convert it to a list???

 

Will

ImkeF
Community Champion
Community Champion

Hi Will,

you use Text.SplitAny for this task:

 

AddColumn = Table.AddColumn(PreviousStep, "New Column", each List.Select(Text.SplitAny([ListColumn], ","), each Text.End(_ ,1)=":" )) 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Thanks! I'll try that.

Do you know of any good resources for explaining to me what lists are and how to use them?

Will
ImkeF
Community Champion
Community Champion

Have a look at the quick reference: https://msdn.microsoft.com/en-US/library/mt186367.aspx

and browse your way through. It gives a good overview of the object/value types.

 

How to use them? Difficult to say. M provides functions specificly for each of type of value where you normally find what you need. But in cases where not (like in your example) it can make sense to transfer your value to a different type because you find the fitting function there.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.