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

Subtract two columns in a table

Hi,

 

I need to subtract two columns in a table. If the user chooses any month from filter then calculated field should show me the difference. Attached picture for reference.

 

Capture.JPGCapture1.JPG

1 ACCEPTED SOLUTION
v-xuding-msft
Community Support
Community Support

Hi @gopi1 ,

I created a sample you can have a try.

  • Create a calendar table and get the month of it.  

 

Table 2 = CALENDARAUTO()
Month = MONTH('Table 2'[Date]) 
  • Create a many-to-one relationship between two tables.

3.PNG

  • create a measure

 

 

Measure = 
var a = SELECTEDVALUE('Table 2'[Month])
var b = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Column] = a && 'Table'[Month] = MAX('Table'[Month])))
var c = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Column] = a && 'Table'[Month] = MAX('Table'[Month])-1))
return
IF(ISFILTERED('Table 2'[Month]), b-c, SUM('Table'[Value]))

1.PNG2.PNG

Here is my sample that you can download.

 

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-xuding-msft
Community Support
Community Support

Hi @gopi1 ,

I created a sample you can have a try.

  • Create a calendar table and get the month of it.  

 

Table 2 = CALENDARAUTO()
Month = MONTH('Table 2'[Date]) 
  • Create a many-to-one relationship between two tables.

3.PNG

  • create a measure

 

 

Measure = 
var a = SELECTEDVALUE('Table 2'[Month])
var b = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Column] = a && 'Table'[Month] = MAX('Table'[Month])))
var c = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Column] = a && 'Table'[Month] = MAX('Table'[Month])-1))
return
IF(ISFILTERED('Table 2'[Month]), b-c, SUM('Table'[Value]))

1.PNG2.PNG

Here is my sample that you can download.

 

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @gopi1 ,

 

Similar is already answerd.

You can give a try.

 

https://community.powerbi.com/t5/Desktop/Difference-between-two-columns-in-matrix-visualisation/td-p...

 

Thanks

Tejaswi

In below function they are pre-defining the values but in my case the month will be in filter. User can choose any months from the filter.

Capture.PNG

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.