Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

SUMX for data from multiple tables

Hi,

 

I have two table from different sources, one having quantity and another having unit price something like below.

 

Below is similar to what we receive from warehouse, which would not have unit price and needs to be filtered only for rows where QUA Qty <>0, meaning items in Quarantine

 
Warehouse NameItemQUA Qty
Warehouse AItem 10
Warehouse AItem 2

10

Warehouse AItem 35
Warehouse BItem 430
Warehouse BItem 525
Warehouse BItem 615

 

Below table looks similar to what we have in ERP system. ERP system has warehouse number and i have seperate mapping table in PowerBI to map warehouse number and name, which is one to one, meaning one warehouse name can be mapped to only one warehouse number and viceversa.

Also in ERP we have project details and unit price for item may differ for each project within same warehouse, like Item 2 and Item 5.

 

Warehouse NumberItemProjectUnit Price
236100Item 1Project A$13.00
236100Item 2Project B$15.00
236100Item 2Project C$12.00
236100Item 3Project C$10.00
236101Item 4Project D$15.00
236101Item 5Project E$26.00
236101Item 5Project A$30.00
236101Item 6Project F$32.00

 

Now i am trying to get a table with two columns viz,. warehouse name and total price of item in QUA (quarantine) for this warehouse.

 

Warehouse A(10 (qty of Item 2 from warehouse table) * AVG($15.00,$12.00) from ERP table) + (5 * AVG($10.00)) + ....
Warehouse B(30 * AVG($15.00)) + (25 * AVG($26.00,$30.00)) + (15 * AVG($32.00)) + ....

 

Please help.

 

5 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi amitchandak ,

       

      Summarize did work and i achieved what i was expecting.

       

      Thank you veru much.

       

  • edhans's avatar
    edhans
    Icon for Community Champion rankCommunity Champion

    You will need to create a unique key between the tables to do this effectively. Most often you see something like:

     

    Sales Price =
       SUMX(
          Sales,
          Sales[Units] * Product[Price]
       )

     

    The product table would be a DIM table that would have something like a ProductID that would relate to a sales record in a Sales FACT table with the same ProductID. The Product Table only has the ID one time - no repeats. The Sales Table can repeat as many times as you like.

     

    Your warehouse/item combo won't work like that the way it is set up. You should have a single field that defines that item. You could do itin Power Query by creating a concatenation of the Warehouse ID and Product ID, then create a similar field in the Sales table. 

     

    In Power BI when you create relationships between tables, those aren't Joins like you would think in a relational database. (They are in the Power Query side, but that isn't where you create measures.) They are filter relationships, and you can only have one active at a time. You cannot even activate 2+ relationships with USERELATIONSHIP(). That will activate an inactive relatinship, but deactivate all others between those two tables. 

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi edhans,

       

      Thank you very much for your response.

       

      I forgot to mention in original query that i have created table 'Item List' with list of unique items from both tables (with Distinct & Union) and are linked to 'Item List' table.

       

       

      • edhans's avatar
        edhans
        Icon for Community Champion rankCommunity Champion

        Then link that field in the Item table to the Warehouse table with the same unique field as a One-to-Many, Single filter, then use something like:

         

        This Measure =
        SUMX(
            Warehouse,
            Item[Price] * Warehouse[Quantity]
        )
        

         

        And I am not 100% clear on your goal. If you are trying to get a single visual combining data from both warehouses, that will be difficult. Not impossible (probably) but difficult. Power BI works best with a star schema, which means one FACT table for all simlar data. You seem to have two FACT tables with the same type of data - two warehouse files. That should be modeled as one table in Power Query through an Append query with a new field that identifies the warehouse.