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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
CL7777
Helper III
Helper III

extracting information from a many to many relationship

hi all, 

I consider myself an advanced beginner dax user and Im having a hard time with this one. suppose i have 2 tables: order table and sales table as below. the red numbers represent the values I want to calculate in a calculated column.

 

order table                                                                       sales table

order #   kit flag  amount                                             order #   summed amt

1                 c           $11                                                    1              $24

2                 c           $12                                                    1              $24

1                 c           $13                                                    2              $12

2                 p           $14                                                    3              $0

3                 p           $15                                                    3              $0

4                 p           $16                                                    3              $0

4                 c           $17                                                     4              $35

4                 c           $18                                                     4              $35

1                 p           $19                                                    1              $24

 

The two tables are connected through a many to many relationship on the order number field. what i want to do is create a calculated column in the sales table that sums up the amount in the order table for any matching order number that has a kit flag of "c". 

 

I apppreciate the help

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @CL7777 

 

Kit C sum  = Calculate(SUM('order'[amount]),sales[Order#]=order[order#] && order[kit flag]="c")

or

Kit C sum  = Calculate(SUM('order'[amount]),FILTER(ALLEXCEPT(sales[Order#]),order[kit flag]="c"))

View solution in original post

V-lianl-msft
Community Support
Community Support

Hi @CL7777 ,

 

Try this:

summed amt =
VAR amt =
    CALCULATE (
        SUM ( 'Order Table'[amount] ),
        FILTER (
            ALLEXCEPT ( 'Order Table', 'Order Table'[order#] ),
            'Order Table'[kit flag] = "c"
        )
    )
RETURN
    IF ( ISBLANK ( amt ), 0, amt )

V-lianl-msft_0-1597714822000.png

 

 

Best Regards,
Liang
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

4 REPLIES 4
amitchandak
Super User
Super User

@CL7777 , Try a formula like, new column in sales

sumx(filter(Order,Order[Order#] = Sales[Order#] && Sales[kit flag] ="c"),Order[amount])

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Ashish_Mathur
Super User
Super User

Hi,

Try this calculated column formula in the Sales table

=calculate(sum('Order'[amount]),filter('order','order'[order #]=earlier('order'[order #])&&'order'[kit flag]="c"))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
V-lianl-msft
Community Support
Community Support

Hi @CL7777 ,

 

Try this:

summed amt =
VAR amt =
    CALCULATE (
        SUM ( 'Order Table'[amount] ),
        FILTER (
            ALLEXCEPT ( 'Order Table', 'Order Table'[order#] ),
            'Order Table'[kit flag] = "c"
        )
    )
RETURN
    IF ( ISBLANK ( amt ), 0, amt )

V-lianl-msft_0-1597714822000.png

 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @CL7777 

 

Kit C sum  = Calculate(SUM('order'[amount]),sales[Order#]=order[order#] && order[kit flag]="c")

or

Kit C sum  = Calculate(SUM('order'[amount]),FILTER(ALLEXCEPT(sales[Order#]),order[kit flag]="c"))

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.