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
ING_BT
Helper I
Helper I

Calculate only IF value in the other table.. Summarize?

Hello, 

 

I'm trying to calculate the sum of Costs, only when a campaign has users. 

 

For that I have these two tables, connected to a join table.

 

The Join table is a distinct of Campaing IDs from Table One. 

Join to Table 1 => Both Direction

Join to Table 2 => One to Many 

 

If I select a whole week (monday to sunday) this is the expected results : 
So, In a table without dates, how can I have the sum of costs only when Users > 0

 

Results
Campaign IDUsersCosts
1455924
2300400

 

Table 1
DateUsersCampagn ID
Monday01
Tuesday01
Wednesday2001
Thursday2501
Friday51
Saturday1502
Sunday1502

 

Table 2
DateCostCampagn ID
Monday501
Tuesday651
Wednesday3231
Thursday5661
Friday351
Saturday2002
Sunday2002

 

Table 3 (join talbe)
Campagn ID
1
2

 

 

Thank you for your help!

 

Best,

Boris

1 ACCEPTED SOLUTION

Hi, @ING_BT 

Yes, you can use function ’USERELATIONSHIP‘ to do it in a neasure.

You need to create a one-to-many  single inactive relationship between table1 and table2.

veasonfmsft_0-1652689473242.png

Then add a new measure 'M_cost' to replace your original filed 'Cost' in your visual table.

M_Cost = CALCULATE(SUM(Table2[Cost]),USERELATIONSHIP(Table1[Date],Table2[Date]),Table1[Users]<>0)

Result:

veasonfmsft_1-1652689593373.png

Best Regards,
Community Support Team _ Eason

View solution in original post

3 REPLIES 3
ING_BT
Helper I
Helper I

Hello Rohit! 

Is there a way to do it in a measure? 
As my model and tables are way more complexe than this, and it doesn't work with many to many relationship like theses ones.

 

Thank you in advance!

Best,

BT

Hi, @ING_BT 

Yes, you can use function ’USERELATIONSHIP‘ to do it in a neasure.

You need to create a one-to-many  single inactive relationship between table1 and table2.

veasonfmsft_0-1652689473242.png

Then add a new measure 'M_cost' to replace your original filed 'Cost' in your visual table.

M_Cost = CALCULATE(SUM(Table2[Cost]),USERELATIONSHIP(Table1[Date],Table2[Date]),Table1[Users]<>0)

Result:

veasonfmsft_1-1652689593373.png

Best Regards,
Community Support Team _ Eason

rohit_singh
Solution Sage
Solution Sage

Hi @ING_BT ,

Please try the following : 

1) Create a calculated table using Table 1 that only has user values > 0

rohit_singh_0-1652190314593.png


2) Modify relationships

rohit_singh_1-1652190345584.png

Table 3 is linked to Table 2 using campaign id
Table 2 is linked to the new calculated table using the date field.

Remove all links to Table 1 (We need to use the calculated table instead)

You should get the below output

rohit_singh_2-1652190508143.png

Hope this helps. Please mark this answer as the solution if it resolves your issue.

Kind regards,


Rohit

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.