Forum Discussion
Sum each group with relation
Hi guys,
I need your help ! I have 2 tables
Table 1 :
| Name | Company | Date | ValueA |
| User1 | Company1 | 01/01/2022 | 10 |
| User2 | Company1 | 01/01/2022 | 17 |
| User3 | Company2 | 01/01/2022 | 30 |
Table 2 :
| Name | Date | ValueB |
| User1 | 01/01/2022 | 2 |
| User2 | 01/01/2022 | 4 |
| User3 | 01/01/2022 | 4 |
| User3 | 01/01/2022 | 3 |
| User2 | 01/01/2022 | 1 |
What I want :
| Name | Date | ValueA | ValueA company | ValueB |
| User1 | 01/01/2022 | 10 | 27 | 2 |
| User2 | 01/01/2022 | 17 | 27 | 5 |
| User3 | 01/01/2022 | 30 | 30 | 7 |
How can I can get this ? I start "ValueA company" with this
CALCULATE(SUM(ValueA),ALLEXCEPT(Table1,date,company)
This formula works sometimes, depends columns I want to display..
For example, If I display "Name" from table2 it will work but if try to display "Name" from both tables the formula will display a very big result..
Any help ?
Thank you
Hi freginier
You can add two custom columns to Table 1 with this DAX expressions:
Value A company = CALCULATE ( SUM ( 'Table 1'[ValueA] ), ALLEXCEPT ( 'Table 1', 'Table 1'[Company] ) )Value B = CALCULATE ( SUM ( 'Table 2'[ValueB] ), FILTER ( ALL ( 'Table 2' ), 'Table 2'[Name] = EARLIER ( 'Table 1'[Name] ) ) )Output:
Sample file attached, please download.
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: www.linkedin.com/in/vahid-dm/
1 Reply
- VahidDM
Super User
Hi freginier
You can add two custom columns to Table 1 with this DAX expressions:
Value A company = CALCULATE ( SUM ( 'Table 1'[ValueA] ), ALLEXCEPT ( 'Table 1', 'Table 1'[Company] ) )Value B = CALCULATE ( SUM ( 'Table 2'[ValueB] ), FILTER ( ALL ( 'Table 2' ), 'Table 2'[Name] = EARLIER ( 'Table 1'[Name] ) ) )Output:
Sample file attached, please download.
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: www.linkedin.com/in/vahid-dm/