cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

Source contains field with List which contains Records -> Find specific entry

Hello,

 

I have a data source (Databricks) where one fields is returned as a list which contains various records.  I know that I can explode the list and then explode the records to get different columns but I would like to avoid this.

 

My interest is to verify the existence of specific values within the records itself and define some flag.

 

As an example, my data source return something like this:

 

Employee #Details
1List
2List

 

When I expand "Details", I get various "records" which then are represented with the following fields: Address, City, State, Country

 

At the end, I would like to simply get a calculated column such as "IsCountryUSA" = True | False if one of the records that belongs to the employee is equals to United States (an employee could have more than one adress).

 

Is there any way to create a calculated column in PowerQuery without actually exploding everything?

Thank you

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User IV
Super User IV

Re: Source contains field with List which contains Records -> Find specific entry

Hi @Dars12 

 

Try this code or please see the attached.

 

let
    Source = #table( type table [Employee = number, Details = list], 
        {
            {
                1, 
                { 
                    [Address="", City="", State="", Country="USA"], 
                    [Address="", City="", State="", Country="UK"] 
                }
            },
            {
                2, 
                { 
                    [Address="", City="", State="", Country="Poland"], 
                    [Address="", City="", State="", Country="UK"] 
                }
            } 
        } 
    ),
    #"Added Custom" = Table.AddColumn(Source, "IsCountryUSA", each List.Contains( Table.FromRecords( [Details] )[Country], "USA" ), type logical )
in
    #"Added Custom"

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn


 

View solution in original post

4 REPLIES 4
Highlighted
Super User IV
Super User IV

Re: Source contains field with List which contains Records -> Find specific entry

@Dars12 , refer to if these functions can help

https://docs.microsoft.com/en-us/powerquery-m/list-functions



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
My Recent Blog -Week is not so Weak Connect on Linkedin

Proud to be a Super User!

Highlighted
Resolver III
Resolver III

Re: Source contains field with List which contains Records -> Find specific entry

Hi, 

 

You can use these functions to achieve this. 

 

 

Table.AddColumn(#"Added Custom", "IsCountryUSA", each List.Contains(Table.Column([Details], "Country"), "USA"))

 

 

 

Let me know if you need any more help!

Highlighted
Super User IV
Super User IV

Re: Source contains field with List which contains Records -> Find specific entry

Hi @Dars12 

 

Try this code or please see the attached.

 

let
    Source = #table( type table [Employee = number, Details = list], 
        {
            {
                1, 
                { 
                    [Address="", City="", State="", Country="USA"], 
                    [Address="", City="", State="", Country="UK"] 
                }
            },
            {
                2, 
                { 
                    [Address="", City="", State="", Country="Poland"], 
                    [Address="", City="", State="", Country="UK"] 
                }
            } 
        } 
    ),
    #"Added Custom" = Table.AddColumn(Source, "IsCountryUSA", each List.Contains( Table.FromRecords( [Details] )[Country], "USA" ), type logical )
in
    #"Added Custom"

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn


 

View solution in original post

Highlighted
New Member

hanks Re: Source contains field with List which contains Records -> Find specific entry

Wow, thanks folks, it works great!

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Community Summit Australia – Join Online!

Community Summit Australia – Join Online!

Be a part of the leading Microsoft Business Applications digital event, curated for the APAC community.

Top Solution Authors
Top Kudoed Authors