Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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 |
1 | List |
2 | List |
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
Solved! Go to Solution.
Hi @Anonymous
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"
Hi @Anonymous
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"
Wow, thanks folks, it works great!
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!
@Anonymous , refer to if these functions can help
https://docs.microsoft.com/en-us/powerquery-m/list-functions
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
100 | |
86 | |
64 |