Forum Discussion

srpeters's avatar
srpeters
Helper II
2 years ago
Solved

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...
  • dufoq3's avatar
    2 years ago

    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

     

    t2

     

    Result

     

    Just replace t1 and t2 codes with your table references.

    You can specify conditions here:

     

    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