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
92502014
New Member

Create dynamic measure to sum the value in one table column if matches value in another table column

Hello Everyone, 

I have two tables:

 

Table 1                                             

ID         Date

3311     10/31/2020

3312      1/5/2021

3313      12/8/2020

 

Table 2

ID          Date                 Revenue      Product

3311       6/1/2020           50                 A

3311      11/30/2021        100               A

3311       2/20/2020         300               B

3311       1/10/2021         200               C

 

How can I create two dynamic measure, before value & after value that will return the revenue if the date in table 2 is before/after the date in table 1?

e.g. 3311 before value will be 50+300 = 350; after value will be 100+200 = 300 (but when I use this meausre, it can still show revenue by product)

 

Thanks!

 

3 ACCEPTED SOLUTIONS
VahidDM
Super User
Super User

Hi @92502014 

 

Try these measures:

 

After value = 
CALCULATE(sum('Table 2'[Revenue]),filter('Table 2','Table 2'[Date]>max('Table 1'[Date])))

 

before value = 
CALCULATE(sum('Table 2'[Revenue]),filter('Table 2','Table 2'[Date]<max('Table 1'[Date])))

 

Output:

 

VahidDM_0-1642026608861.png

 

 

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/

 

 

View solution in original post

Thanks! I should include more value in the table 2, my bad! Is there a way to match the ID as well?

 

In fact, I also have multiple IDs in table 2, so I need to match the ID as well.

Table 1                                             

ID         Date

3311     10/31/2020

3312      1/5/2021

3313      12/8/2020

 

Table 2

ID          Date                 Revenue      Product

3311       6/1/2020           50                 A

3311      11/30/2021        100               A

3311       2/20/2020         300               B

3311       1/10/2021         200               C

3312       3/7/2020           10                 A

3313       8/18/2020         100               C

View solution in original post

@92502014 

 

Connect your tables (Relationship) with the ID columns, then test my codes, I think those codes would work well.

 

Let me know if you ran into any problem.

 

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/

 

 

View solution in original post

3 REPLIES 3
VahidDM
Super User
Super User

Hi @92502014 

 

Try these measures:

 

After value = 
CALCULATE(sum('Table 2'[Revenue]),filter('Table 2','Table 2'[Date]>max('Table 1'[Date])))

 

before value = 
CALCULATE(sum('Table 2'[Revenue]),filter('Table 2','Table 2'[Date]<max('Table 1'[Date])))

 

Output:

 

VahidDM_0-1642026608861.png

 

 

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/

 

 

Thanks! I should include more value in the table 2, my bad! Is there a way to match the ID as well?

 

In fact, I also have multiple IDs in table 2, so I need to match the ID as well.

Table 1                                             

ID         Date

3311     10/31/2020

3312      1/5/2021

3313      12/8/2020

 

Table 2

ID          Date                 Revenue      Product

3311       6/1/2020           50                 A

3311      11/30/2021        100               A

3311       2/20/2020         300               B

3311       1/10/2021         200               C

3312       3/7/2020           10                 A

3313       8/18/2020         100               C

@92502014 

 

Connect your tables (Relationship) with the ID columns, then test my codes, I think those codes would work well.

 

Let me know if you ran into any problem.

 

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/

 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.