Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
gunasai
Helper I
Helper I

Measures, relationships and/or Joins?

Hey guys,

 

I have an Order_header table (a main table) as follows through which I made a 1-many relationship with other tables. More info below.

 

Ord_numOrd_cust_nameOrd_status_code
1111ABCOpen

 

I have a pick detail table as follows where Item/s in the above order is being picked with its shipment number.

 

Note: There are many shipments for an order and because I only care about the recent shipment, I am showing only the items being picked for the most recent shipment.

 

Item_codeQty_to_pickQty_pickedShipment_num
110003
2100003
3003

 

I made a 1-many relationship between the above 2 tables (because I wanted to filter out the rows in pick_det from order_header) and I made the following table as a visual on my dashboard.

 

Ord_numOrd_cust_nameItem_codeQty_to_pickQty_pickedOrd_status_code

1111

ABC11000Open
1111ABC210000Open
1111ABC300Open

 

 

Now, my question is as follows, I have another table (order_detail) that has the following,

 

Ord_numItem_codeSales_price
1111110
1111220
1111330
1111440
1111550
1111660

 

I only care about Item_codes 1,2,3 because 4,5,6 already went in previous shipments.

 

Finally, I want to get the following table,

Ord_numOrd_cust_nameItem_codeQty_to_pickQty_pickedShipment_numOrd_status_codeSales_priceTotal_price (qty_to_pick*sales_price)
1111ABC110003Open101000
1111ABC2100003Open2020000
1111ABC3003Open300

 

I cannot join pick_det and order_detail tables (because Order_header is connected to both with a 1-many relationship)

 

How do I join pick_det and order_detail? Is there any measure I can write so I can finally make the above "total_price" calculation?

 

I basically have a star schema right now with order_header as the main table that has a 1-many relationship on Ord_num with both pick_det and order_detail table.

 

Thanks in advance. I am sorry if the question wasn't easy to understand.

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @gunasai ,

You can create two measures as below to get the total price, please find the attachment for the details.

Temp_tprice = 
SUM ( 'pick_det'[Qty_to_pick] )
    * CALCULATE (
        SUM ( 'order_detail'[Sales_price] ),
        FILTER (
            'order_detail',
            'order_detail'[Ord_num] = SELECTEDVALUE ( 'Order_header'[Ord_num] )
                && 'order_detail'[Item_code] = SELECTEDVALUE ( 'order_detail'[Item_code] )
        )
    )
Total_price = 
SUMX (
    VALUES ( 'pick_det'[Item_code] ),
    SUMX (
        GROUPBY (
            'Order_header',
            'Order_header'[Ord_num],
            'Order_header'[Ord_cust_name],
            'Order_header'[Ord_status_code]
        ),
        [Temp_tprice]
    )
)

yingyinr_0-1631240278751.png

Best Regards

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

View solution in original post

2 REPLIES 2
gunasai
Helper I
Helper I

Thank you so much! 🙂

v-yiruan-msft
Community Support
Community Support

Hi @gunasai ,

You can create two measures as below to get the total price, please find the attachment for the details.

Temp_tprice = 
SUM ( 'pick_det'[Qty_to_pick] )
    * CALCULATE (
        SUM ( 'order_detail'[Sales_price] ),
        FILTER (
            'order_detail',
            'order_detail'[Ord_num] = SELECTEDVALUE ( 'Order_header'[Ord_num] )
                && 'order_detail'[Item_code] = SELECTEDVALUE ( 'order_detail'[Item_code] )
        )
    )
Total_price = 
SUMX (
    VALUES ( 'pick_det'[Item_code] ),
    SUMX (
        GROUPBY (
            'Order_header',
            'Order_header'[Ord_num],
            'Order_header'[Ord_cust_name],
            'Order_header'[Ord_status_code]
        ),
        [Temp_tprice]
    )
)

yingyinr_0-1631240278751.png

Best Regards

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.