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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors