Forum Discussion

Jtbonner1986's avatar
Jtbonner1986
Helper I
3 years ago
Solved

Fix a Many to Many relationship? How to build correct data model...

Hi Everyone, 

 

I have an issue i want to resolve and im not sure of the best way;

 

I have two tables with mulitple rows for 'Material ID'; one is a 'Demand' table and one is a 'Product' Table. I want to be able to filter on one 'Material ID' and for it to return only the values of that material in the demand table. 

 

The tables are structured like the below

 

Demand Table 

Material No.Date RequiredQuantity
12301/02/202350
45601/02/202325
78901/02/202310
12301/03/202310
12301/04/20235
12301/02/202310

 

Product Table

 

Product IDMaterial IDQTY Needed
AAA1235
AAA7891
BBB9991
BBB1231
CCC5551
CCC12310

 

I want to create a Matrix visual that displays the Demand table like the below (using a pre created Calendar table)

 

and i want to be able to filter by Product ID - and for it toonly return the Material ID relating to the product. 

 

Material ID01/02/202301/03/202301/04/2023
12360105
45625  
78910 

 

 

But i am unbable to join both tables on Material ID as there are multiple rows for this in the Demand and the Product table as a single material can below to multiple products

 

any help is really appreciated 

 

Many thanks,

Josh

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Jtbonner1986 ,

    Please create a measure like:

    Measure = 
    VAR _material = SELECTEDVALUE('Product'[Material ID])
    VAR _value = CALCULATE(SUM('Demand'[Quantity]),'Demand'[Material No.]=_material)
    RETURN
    _value

    Output:

    Please check the pbix file.

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

6 Replies