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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
johnstrang
Frequent Visitor

Find differences between 2 selected rown in a table

Hello everyone,

 

In my work we have monthly mailing campaigns to selected donors from our database, where each campaign record has a number of fields, for example

  • Number of people mailed
  • Number of reponses with donation
  • Value of donations received

What I want to do is simply select 2 campaigns by their reference number (via a filter) and calculate the differences in these values.

 

A very simple example:

CampaignNr MailedNr ResponsesValue of Donations
111111000502000
222221100401900
Differences-10010100

 

Displaying the values for each campaign is very easy, but finding the differences is not ...

 

Any suggestions gratefully received!

 

Thank you in advance and kind regards,

John

2 ACCEPTED SOLUTIONS
mark_endicott
Super User
Super User

@johnstrang - This will take multiple steps.

 

1) Set up two DAX Calculated tables that will allow you to select a Campaign:

 

Campaign 1 = VALUES( 'Table'[Campaign] )

Campaign 2 = VALUES( 'Table'[Campaign] )

 

2) If you get a relationship created with either of these tables, ensure they are deleted. 

 

3) Create a measure that finds the values you want based on a slicer selection and then performs the calculation:

 

Difference = 

VAR _campaign_1 = SELECTEDVALUE( 'Campaign 1'[Campaign] )

VAR _campaign_2 = SELECTEDVALUE( 'Campaign 2'[Campaign] )

VAR _value_campaign_1 = CALCULATE( SUM( 'Table'[Column] ), KEEPFILTERS( 'Table'[Campaign] = _campaign_1 ))

VAR _value_campaign_2 = CALCULATE( SUM( 'Table'[Column] ), KEEPFILTERS( 'Table'[Campaign] = _campaign_2 ))

RETURN
_value_campaign_2 - _value_campaign_1

 

Just replace my 'Table' and [Column] references with the names from your model. 

 

If I answered your question please mark my post as the solution, it helps others with the same challenge find the answer!

View solution in original post

v-tejrama
Community Support
Community Support

Hi @johnstrang ,

 

After thoroughly reviewing the details you provided, I was able to reproduce the scenario, and it worked on my end. I have used the sample data on my end and successfully implemented it.  


I am also including .pbix file for your better understanding, please have a look into it:

 

Hope this will help you resolve your issue, if you need any further assistance, feel free to reach out.


If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

Thank you for using Microsoft Community Forum.

Tejaswi

View solution in original post

4 REPLIES 4
v-tejrama
Community Support
Community Support

Hi @johnstrang ,

 

After thoroughly reviewing the details you provided, I was able to reproduce the scenario, and it worked on my end. I have used the sample data on my end and successfully implemented it.  


I am also including .pbix file for your better understanding, please have a look into it:

 

Hope this will help you resolve your issue, if you need any further assistance, feel free to reach out.


If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

Thank you for using Microsoft Community Forum.

Tejaswi

Thank you so much - this works well. I now need to duplicate the various measures I need to complete my report.

 

Regards,

John

mark_endicott
Super User
Super User

@johnstrang - This will take multiple steps.

 

1) Set up two DAX Calculated tables that will allow you to select a Campaign:

 

Campaign 1 = VALUES( 'Table'[Campaign] )

Campaign 2 = VALUES( 'Table'[Campaign] )

 

2) If you get a relationship created with either of these tables, ensure they are deleted. 

 

3) Create a measure that finds the values you want based on a slicer selection and then performs the calculation:

 

Difference = 

VAR _campaign_1 = SELECTEDVALUE( 'Campaign 1'[Campaign] )

VAR _campaign_2 = SELECTEDVALUE( 'Campaign 2'[Campaign] )

VAR _value_campaign_1 = CALCULATE( SUM( 'Table'[Column] ), KEEPFILTERS( 'Table'[Campaign] = _campaign_1 ))

VAR _value_campaign_2 = CALCULATE( SUM( 'Table'[Column] ), KEEPFILTERS( 'Table'[Campaign] = _campaign_2 ))

RETURN
_value_campaign_2 - _value_campaign_1

 

Just replace my 'Table' and [Column] references with the names from your model. 

 

If I answered your question please mark my post as the solution, it helps others with the same challenge find the answer!

Hi Mark

 

Many thanks for your prompt response - I'll give it a go and let you know how it works.

 

Regards,

John

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.