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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors