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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Merleau
Helper II
Helper II

Converting list elements based on their lengths

Hello,

One column in my table is a list of strings. I would like to change the strings to lower case if their lenghts is greater than 1.

 

Name      Types
N1   A,ABC,B,CDF,DF
N2H,JKL,BG,DC,C

 

Convert to

Name      Types
N1   A,abc,B,cdf,df
N2H,jkl,bg,dc,C

 

Can somebody help?

Thank you

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

Here is one way to do this...

= Table.TransformColumns(previousQueryStep, {{"Types", each Text.Combine(List.Transform(Text.Split(_, ","), each if Text.Length(_) > 1 then Text.Lower(_) else _), ","), type text}})

Using your example table you end up with...

jgeddes_0-1733415354730.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

4 REPLIES 4
ThxAlot
Super User
Super User

For fun only, to incorporate the power of regex,

 

import re
import numpy as np
df['Types']=np.vectorize(lambda string:re.compile(r'[a-z]{2,}(?=\b)',flags=re.I).sub(lambda match:str.lower(match.group(0)),string))(df['Types'])
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8jNUUFBQ0lFy1HF0ctZx0nF2cdNxcVOK1QFKGQHFPXS8vH10nNx1XJx1nJViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Types = _t]),
    #"Run Python script" = Python.Execute("import re#(lf)import numpy as np#(lf)df['Types']=np.vectorize(lambda string:re.compile(r'[a-z]{2,}(?=\b)',flags=re.I).sub(lambda match:str.lower(match.group(0)),string))(df['Types'])",[df=Source]),
    df = #"Run Python script"{[Name="df"]}[Value]
in
    df

 

ThxAlot_2-1733444646849.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



AlienSx
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8jNUUFBQ0lFy1HF0ctZx0nF2cdNxcVOK1QFKGQHFPXS8vH10nNx1XJx1nJViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Name      " = _t, Types = _t]),
    chars = List.Buffer({"a".."z", "A".."Z"}), 
    result = Table.TransformColumns(
        Source, 
        {
            "Types", 
            (x) => Text.Combine(
                List.Transform(
                    Text.Split(x, ","), 
                    (w) => if List.Contains(chars, w) then w else Text.Lower(w)
                ),
                ","
            )
        }
    )
in
    result
jgeddes
Super User
Super User

Here is one way to do this...

= Table.TransformColumns(previousQueryStep, {{"Types", each Text.Combine(List.Transform(Text.Split(_, ","), each if Text.Length(_) > 1 then Text.Lower(_) else _), ","), type text}})

Using your example table you end up with...

jgeddes_0-1733415354730.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thank you @jgeddes 

This is perfect!

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.