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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
srpeters
Helper II
Helper II

Creating a new table based off of multiple conditionals

Hello,
 
I have a table with a lot of information I need and another with only one column I need. My problem is that there are a lot of duplicate values in both tables and there does not seem to be a way for me to remove these duplicates without messing up the correct data. I was wondering if there was a way to make a new table that only pulls in a column if it passes three different conditionals. For example, lets say I have a table about animals and there were these columns of data: Name, color, type, breed, and location. Then a second table with Name and Amount for its columns. Could I make a new table in Power Query that only included animals with Names and Amounts (from the second table) where the color is 'blue', the type is 'mamal' and the 'breed' is 'shorthair'(from that first table)? 
 
Thank you in advance!

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @srpeters

for future requests don't forget to provide sample data as table and also expected result (based on sample data).

I'm not sure if you want this exactly:

 

t1

dufoq3_0-1710006455002.png

 

t2

dufoq3_1-1710006475977.png

 

Result

dufoq3_2-1710006493742.png

 

Just replace t1 and t2 codes with your table references.

You can specify conditions here:

dufoq3_3-1710006557188.png

 

let
    t1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY1BCoMwEEXvkrWXEGk3pVCaumnIYloHIyaTMkaKt3cSFKF0M5/5PN43RtXUMX5VpV5+RokrBPCSk4ucJFutbGWk5jSQ/Iyd3JPHjwPKgI/U56bdORwPW9hsG3S+F+iGCVneyED9v1F9KVzjeJhkFooQ3lkcIo24HMrmWVCNXEw/u7uwfihrVw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Color = _t, Type = _t, Breed = _t, Location = _t]),
    t2 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsxLKUotV9JRMjRQitWJVgpILUktAnKNIFznjKLM4pLMvESgkDFEKDi1KD0VyDWBcH0Ti1KzgVxTOBeoHMg3A/JjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Amount = _t]),
    // Enter as lower text!
    Conditions = [ Color = "blue",
    Type = "mamal",
    Breed = "short" ],
    Ad_t1 = Table.AddColumn(t2, "t1", each Table.SelectRows(t1, (x)=> Text.Lower(x[Color]) = Conditions[Color] and Text.Lower(x[Type]) = Conditions[Type] and Text.Lower(x[Breed]) = Conditions[Breed]){[Name = [Name]]}?, type table),
    FilteredRows = Table.SelectRows(Ad_t1, each [t1] <> null),
    RemovedColumns = Table.RemoveColumns(FilteredRows,{"t1"})
in
    RemovedColumns

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

2 REPLIES 2
dufoq3
Super User
Super User

Hi @srpeters

for future requests don't forget to provide sample data as table and also expected result (based on sample data).

I'm not sure if you want this exactly:

 

t1

dufoq3_0-1710006455002.png

 

t2

dufoq3_1-1710006475977.png

 

Result

dufoq3_2-1710006493742.png

 

Just replace t1 and t2 codes with your table references.

You can specify conditions here:

dufoq3_3-1710006557188.png

 

let
    t1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY1BCoMwEEXvkrWXEGk3pVCaumnIYloHIyaTMkaKt3cSFKF0M5/5PN43RtXUMX5VpV5+RokrBPCSk4ucJFutbGWk5jSQ/Iyd3JPHjwPKgI/U56bdORwPW9hsG3S+F+iGCVneyED9v1F9KVzjeJhkFooQ3lkcIo24HMrmWVCNXEw/u7uwfihrVw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Color = _t, Type = _t, Breed = _t, Location = _t]),
    t2 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsxLKUotV9JRMjRQitWJVgpILUktAnKNIFznjKLM4pLMvESgkDFEKDi1KD0VyDWBcH0Ti1KzgVxTOBeoHMg3A/JjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Amount = _t]),
    // Enter as lower text!
    Conditions = [ Color = "blue",
    Type = "mamal",
    Breed = "short" ],
    Ad_t1 = Table.AddColumn(t2, "t1", each Table.SelectRows(t1, (x)=> Text.Lower(x[Color]) = Conditions[Color] and Text.Lower(x[Type]) = Conditions[Type] and Text.Lower(x[Breed]) = Conditions[Breed]){[Name = [Name]]}?, type table),
    FilteredRows = Table.SelectRows(Ad_t1, each [t1] <> null),
    RemovedColumns = Table.RemoveColumns(FilteredRows,{"t1"})
in
    RemovedColumns

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.