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
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
pranit828
Community Champion
Community Champion

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"))





PBI_SuperUser_Rank@1x.png


Hope it resolves your issue? 
Did I answer your question? Mark my post as a solution!

Appreciate your Kudos, Press the thumbs up button!!
Linkedin Profile

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])

 

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.

pranit828
Community Champion
Community Champion

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"))





PBI_SuperUser_Rank@1x.png


Hope it resolves your issue? 
Did I answer your question? Mark my post as a solution!

Appreciate your Kudos, Press the thumbs up button!!
Linkedin Profile

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.