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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
olimilo
Continued Contributor
Continued Contributor

If Value.Type is list then combine all items otherwise get the actual value?

With the following sample table, is it possible to check if the value from the [data] column is of type List, then combine all the items into one type Text value, otherwise just get the given value from the [data] column? The value of the List row should all be text values.

 

data
{List}
1/1/2020
Passed

 

Basically the output would be (if the {List} contains {"one", "two", "three"}):

 

data
one, two, three
1/1/2020
Passed

 

I tried the query below but I'm getting a "can't convert [Data] value to List" error:

 

 

 

= Table.AddColumn(#"Prev Step", "Custom", each if Value.Is(Value.Type([data]), type text) then [data] else List.Combine([data]))

 

 

 

1 ACCEPTED SOLUTION
edhans
Super User
Super User

See if this returns what you need @olimilo 

 

let
    Source = Table.FromList(
    {
        [Data = 1],
        [Data = {1,2,3}],
        [Data = #date(2020,1,1)]
    },
    Record.FieldValues,
    {"Data"}
),
    #"Added Custom" = 
        Table.AddColumn(
            Source, 
            "Custom", 
            each 
            if Value.Is([Data], type list) = true
            then Text.Combine(List.Transform([Data], Text.From), ", ")
            else null
        )
in
    #"Added Custom"

 

Here my list is numbers, but Text.From converts to text for the concatenation.

edhans_0-1598975397039.png

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.

 

You can replace the "else null" part of the function above to "else [Data] to pull the Data column value.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

10 REPLIES 10
Icey
Community Support
Community Support

Hi @olimilo ,

 

Is this problem solved?

 

If it is solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

 

If not, please let me know.

 

 

Best Regards,

Icey

edhans
Super User
Super User

See if this returns what you need @olimilo 

 

let
    Source = Table.FromList(
    {
        [Data = 1],
        [Data = {1,2,3}],
        [Data = #date(2020,1,1)]
    },
    Record.FieldValues,
    {"Data"}
),
    #"Added Custom" = 
        Table.AddColumn(
            Source, 
            "Custom", 
            each 
            if Value.Is([Data], type list) = true
            then Text.Combine(List.Transform([Data], Text.From), ", ")
            else null
        )
in
    #"Added Custom"

 

Here my list is numbers, but Text.From converts to text for the concatenation.

edhans_0-1598975397039.png

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.

 

You can replace the "else null" part of the function above to "else [Data] to pull the Data column value.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Jimmy801
Community Champion
Community Champion

Hello @olimilo 

 

to the perfect answer of @edhans i just want to show an example how to do it without adding a column, but with a transform of the column instead. @edhans I used your code as a basic if you don't mind 🙂

let
    Source = Table.FromList(
    {
        [Data = 1],
        [Data = {1,2,3}],
        [Data = #date(2020,1,1)]
    },
    Record.FieldValues,
    {"Data"}
),
    Trans = 
        Table.TransformColumns(
            Source, 
            {
                {
                    "Data", 
                    each 
                    if Value.Is(_, type list) = true
                    then Text.Combine(List.Transform(_, Text.From), ", ")
                    else _
                }
            }
        )
in
    Trans

 

BR

 

JImmy

olimilo
Continued Contributor
Continued Contributor

Hi @Jimmy801 & @edhans,

Both solutions worked perfectly for me! Thank you very much for the help!

Jimmy801
Community Champion
Community Champion

Hello @olimilo 

 

then it would be great if you would mark both answers as solution

 

BR

 

Jimmy

Anonymous
Not applicable

even if @mumbaicharaja  hasn't promoted the answer to solution yet, you used the syntax used here, for a structure that contains nested tables

 

 

 

if Value.Is(c{0}, type table) 

 

 

 

 and I think is correct.

The problem instead lies in the argument of List.Combine function

which expect  a list of list

List.Combine({{1, 2}, {3, 4}})

 

try using Text.Combine([Data],",")

 

 

 

let
    Source = Table.FromRecords({[col={"111","222","333"}],[col="aaa"],[col="bbb"]}),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each if Value.Is([col], type list)  then Text.Combine([col],",") else [col])
in
    #"Added Custom"

 

 

image.png

ziying35
Impactful Individual
Impactful Individual

@olimilo 

 

= Table.AddColumn(#"Prev Step", "Custom", each if [data] is list then List.Combine([data]) else [data])

olimilo
Continued Contributor
Continued Contributor

Hi@ziying35 

Thanks however I'm getting this error for all items under the [data] column: We cannot convert the value "xyz" to type List. The "xyz" there is the first value that appears on the list. The same error is raised even if there's only one item in the list.

 

olimilo_0-1598968790544.png

 

The list item in the screenshot would have the values: {"Indonesia", "Malaysia"}.

ziying35
Impactful Individual
Impactful Individual

@olimilo 

I'm sorry, I made a mistake in the previous code. Try this:

 

= Table.AddColumn(#"Prev Step", "Custom", each if [data] is list then Text.Combine([data], ",") else [data])

Greg_Deckler
Community Champion
Community Champion

@olimilo - Maybe using Type.Is and List.Accumulate but someone like @ImkeF or @edhans would know better. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.

Top Kudoed Authors