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
Anonymous
Not applicable

Add columns that contain filtered sums from another table

I have a table of campaigns. I want to add columns to my campaign table that contain the number of opportunities at each sales stage. I have a table of opportunities with columns for stage number and stage name. 

 

Campaigns

Screenshot 2019-05-30 13.09.03.png

 

Opportunities

Screenshot 2019-05-30 13.09.18.png

 

These two table have a relationship

Screenshot 2019-05-30 13.10.40.png

 

How can I add columns to the campaigns table that summarize the number of opportunities at each stage? I would add a column for each of the 9 sales stages: Investigate, Meet, Probe, Apply, Convince, Tie it up, Closed Won-Pending, Closed Won, Dead. 

 

Thanks in advance for your help.

Jeff

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I can't test it right now, but you have a bidirectional relationship, so you can make use of the RELATEDTABLE.


When you are in the CAMPAIGN table, the RELATEDTABLE function will return the rows in the OPPORTUNITY which are filtered, for each row.

So if you add a calculated column and use this code

 

rows=countrows(RELATEDTABLE(opportunity))

it will tell you the number of connected rows.

 

Now the trick is to filter them based on your stage, so (again without testing but should work), something in the line of 

Rows in Stage Investigation=countrows(FILTER(relatedtable(opportunity);Stage="investigation"))

or probably better

Rows in stage investigation = calculatetable(opportunity;Stage="Investigation")

View solution in original post

4 REPLIES 4
TomMartens
Super User
Super User

Hey,

 

I think you are looking for the LOOKUPVALUE function: https://dax.guide/lookupvalue/

If you have to aggregate multiple rows from the source table you can use something similar to this:

column name = 
var thisCampaignID  = '<campaigntable>'[campaignid]
return
CALCULATE(
	SUM('<opportunitytable>'[colums])
	FILTER(
		'<opportunitytable>'
		, '<opportunitytable>'[campaignid] = thisCampaignID
	)
)


Hopefully this is what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

I can't test it right now, but you have a bidirectional relationship, so you can make use of the RELATEDTABLE.


When you are in the CAMPAIGN table, the RELATEDTABLE function will return the rows in the OPPORTUNITY which are filtered, for each row.

So if you add a calculated column and use this code

 

rows=countrows(RELATEDTABLE(opportunity))

it will tell you the number of connected rows.

 

Now the trick is to filter them based on your stage, so (again without testing but should work), something in the line of 

Rows in Stage Investigation=countrows(FILTER(relatedtable(opportunity);Stage="investigation"))

or probably better

Rows in stage investigation = calculatetable(opportunity;Stage="Investigation")
Anonymous
Not applicable

Thanks, Tom. I'm not sure that does what I need. 

 

From the opportunity table I need to count the rows that contain a particular value from the stage number column. and put that value into a column into a row the campaigns table, based on the campaign ID. 

 

Where would I apply the Dax you suggested? Would that be used to create a custom column in the quiery editor? Or would I use that to create a new column in the report?

Hey, consider to create a calculated column. This article explains it very detailed: https://www.jetglobal.com/blog/calculated-columns-vs-measures/

Regards,
Tom


Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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.