cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
KellyB Frequent Visitor
Frequent Visitor

Measure or column? How to sum data from two unrelated tables

Hi!

 

I’m working with two large datasets that aren’t related. Neither table has a column of unique values.

 

I need to create charts that show the stock level from each store in both datasets by item name, region name, and store name.

 

I’ve tried to make a clustered column chart with a measure but I end up with stuff on the chart that Power BI calls (Blank). Looking closely at the (Blank) stuff shows that Power BI is calling items in one of the tables (Blank) rather than the actual item name.

 

Then I tried to make a new column in a table that just had a list of all the different stock items but then the clustered column charts shows that all stores have the same stock levels.

 

How can I sum the stock levels from the two datasets and display them on a chart?

 

Thanks in advance!

 

Here are examples of what my datasets are like:

Fruit Stands-National data.PNGNational DataFruit Stands-Local Info.PNGLocal InfoFruit Stands-Goal chart.PNGThis is what I want to get displayed.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Measure or column? How to sum data from two unrelated tables

Hi @KellyB,

 

You can create two tables to store merged 'shop' records and 'product' records, then use shop table as axis, product as legend to create a clustered column chart.


After these, write a measure to summary records from two tables and use it in value field.

 

Calculate tables:

 

DimShop=
DISTINCT(UNION(VALUES(TABLE1[Shop]),VALUES(TABLE2[Store])))

DimProduct=
DISTINCT(UNION(VALUES(TABLE1[Product]),VALUES(TABLE2[Item])))

 

 

Measure formula:

 

Measure =
VAR summary =
    UNION (
        SELECTCOLUMNS ( TABLE1, "Shop", [Shop], "Product", [Product], "Stock", [Stock] ),
        SELECTCOLUMNS ( TABLE2, "Shop", [Store], "Product", [Item], "Stock", [Quanity] )
    )
RETURN
    SUMX (
        FILTER (
            summary,
            [Shop] IN VALUES ( DimShop[Shop] )
                && [Product] IN VALUES ( DimProduct[Product] )
        ),
        [Stock]
    )

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.



For learning resources/Release notes, please visit: | |
4 REPLIES 4
Super User
Super User

Re: Measure or column? How to sum data from two unrelated tables

Power BI does support many-to-many now and you could create a bridge table. Also, perhaps you could create a concatenated column that uniquely identifies each shop (shop & region). Generally you get blanks in Power BI when things don't quite match up.


Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!


KellyB Frequent Visitor
Frequent Visitor

Re: Measure or column? How to sum data from two unrelated tables

Hi Greg,

 

I can't find a many-to-many option in the Edit Relationships window and Power BI gives me an error when I try to relate the Item and Product columns saying that one column must have unique values.

 

Is my version of Power BI recent enough to have the many-to-many relationship? Where would it be located?

 

Thanks so much for your help!!

 

Power BI program info.PNG

Community Support Team
Community Support Team

Re: Measure or column? How to sum data from two unrelated tables

Hi @KellyB,

 

You can create two tables to store merged 'shop' records and 'product' records, then use shop table as axis, product as legend to create a clustered column chart.


After these, write a measure to summary records from two tables and use it in value field.

 

Calculate tables:

 

DimShop=
DISTINCT(UNION(VALUES(TABLE1[Shop]),VALUES(TABLE2[Store])))

DimProduct=
DISTINCT(UNION(VALUES(TABLE1[Product]),VALUES(TABLE2[Item])))

 

 

Measure formula:

 

Measure =
VAR summary =
    UNION (
        SELECTCOLUMNS ( TABLE1, "Shop", [Shop], "Product", [Product], "Stock", [Stock] ),
        SELECTCOLUMNS ( TABLE2, "Shop", [Store], "Product", [Item], "Stock", [Quanity] )
    )
RETURN
    SUMX (
        FILTER (
            summary,
            [Shop] IN VALUES ( DimShop[Shop] )
                && [Product] IN VALUES ( DimProduct[Product] )
        ),
        [Stock]
    )

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.



For learning resources/Release notes, please visit: | |
KellyB Frequent Visitor
Frequent Visitor

Re: Measure or column? How to sum data from two unrelated tables

Hi Xiaoxin Sheng,

 

Thanks for this solution. It worked!

 

Sorry for the large time lag between your response and my reply. It took me a bit to try to understand the solution and work with it.

 

Thanks so much!