Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Add unique values to a column retrieved from multiple tables in PowerBI

I currently have two tables (Excel sheets) related to each other in PowerBI: Inventory; columns (Article number, description, quantity, sumOfQuantityReceived) MaterialsReceived; columns (Articl...
  • TomMartens's avatar
    5 years ago

    Hey Anonymous ,

     

    I use this DAX statement to create a table that contains "unique" values from multiple tables:

    New Table = 
    DISTNCT(
        UNION(
            ALLNOBLANKROWS( 'table1'[columname] )
            , ALLNOBLANKROWS( 'table2'[columname] )
        )
    )

    Hopefully, this provides what you are looking for.

     

    Regards,

    Tom

  • AlB's avatar
    5 years ago

    Hi Anonymous 

    See it all at work in the attached file.

    You can create a calculated table in DAX:

    Option1 =
    DISTINCT (
        UNION (
            DISTINCT ( InventoryT[Article number] ),
            DISTINCT ( MaterialsReceived[Article number] )
        )
    )

     

    or create a table in the query editor. Place the following M code in a blank query to see the steps.

    let
        T1 = Table.SelectColumns(InventoryT, "Article number"),
        T2 = Table.SelectColumns(MaterialsReceived, "Article number"),
        res_ = Table.Distinct(Table.Combine({T1,T2}))
    in
        res_

     

     

     

     

    Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.