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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.