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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
stanislav_dugas
Helper III
Helper III

2 conditions for Sum between 2 tables

Hi PBI experts.

 

I am having an issue with writing a dax formula for this.

I have 2 tables which have both way relationship many to one.

 

1st table

IDPeriodTypeValue
12020a1
12020b2
12020c3
22020a4
22020b5
22020c6
32020a7
32020b8
32020c9
12021a10
12021b11
12021c12
22021a13
22021b14
22021c15
32021a16
32021b17
32021c18

 

2nd table 

IDSum Year 2020 type aSum Year 2021 type a
1  
2  
3  

 

What i need to do is create sum of Values for each ID in table 2 where year = "2020" and type = "a" based table 1.

 

The data above are just example since the real date are more complex and the type has several subtypes which would be combined together on that level.

 

Thank you all for ideas.

1 ACCEPTED SOLUTION

Please try this expression instead.  Also, why do you have a bi-directional relationship?  You should make that single direction.  This should work in a table visual with the ID column from your 2nd table.

 

NewMeasure = CALCULATE(SUM(Table1[Values], Table1[Type] = "a", Table1[Period] = "2020")

 

If your Period column is number type, remove the quotes on 2020.

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@stanislav_dugas 

You can achieve this using  a matrix visual and slicer with a simple masure like": 

Total = SUM(Table1[Value])
 
Screenshot 2020-11-08 113036.png
 
If you want to hard-code then try, this measure: 
2020 - A Total = CALCULATE( SUM(Table1[Value]) , Table1[Period] = 2020 , Table1[Type] = "a" )

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn 
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

stanislav_dugas
Helper III
Helper III

So far i tried to create something like this but i am getting overall number for whole column rather then for individual ID.

 

CALCULATE(SUM(Table1[Values]),FILTER(Table1,AND(Table1[Type]="a",Table1[Period]="2020")))

Please try this expression instead.  Also, why do you have a bi-directional relationship?  You should make that single direction.  This should work in a table visual with the ID column from your 2nd table.

 

NewMeasure = CALCULATE(SUM(Table1[Values], Table1[Type] = "a", Table1[Period] = "2020")

 

If your Period column is number type, remove the quotes on 2020.

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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