Sometimes we fall into a situation where we need to calculate columns difference in Matrix. Something likes image1

Let’s go through with following steps to achieve this output in Matrix. I believe that you already have created required column and row group in your matrix. The following steps are additional work to achieve the column difference in the matrix.

Image1 |

Step 1. Create a calculated column in the dataset named as

**ColumnDiff**and assign this expression under Field Source
="Diff : "+Format(Cdate(Fields!OrderDate.Value),"MM-yyyy")+" - "+DateAdd(DateInterval.Month,-1,Cdate(Fields!OrderDate.Value)).ToString("MM-yyyy")

Image2 |

Refer image2 regarding this step.

Step 2. Now select the matrix and create a new

**Parent Group**under your**Column Groups**Image3 |

Refer image3 regarding this step.

Choose

**[ColumnDiff]**field as a**Group by**expression and click ok button.Image4 |

Refer image4 regarding this step.

Now click on newly created column group and give an approprite name as

**grp_ColumnDiff**. Because we will use this group name in a expression in next step.Image5 |

Refer image5 regarding this step.

Step 3. Now use following expression in your child group row &

**[ColumnDiff]**column cell.
=SUM(Fields!TotalAmount.Value)-Previous(SUM(Fields!TotalAmount.Value),"grp_ColumnDiff")

Refer image6 regarding this step.

Image6 |

Let’s discuss the above expression.

SUM(Fields!TotalAmount.Value) will give the total value for the current column group and Previous(SUM(Fields!TotalAmount.Value),"grp_ColumnDiff") will give the total value of the previous column group corrosponding to

**grp_ColumnDiff**column group
Step 4. Now set the following column visibilty expression for the last column that says

**[ColumnDiff]**
=CBOOL(Cdate(Fields!OrderDate.Value).Month mod 2)

Refer image7 regarding this step.

Image7 |

This expression will return True for ODD month number and False for even month number.

You need to only change the report connection to appropriate connection string to execute this report at your own enviornment. This sample is designed in SSRS2008R2 version. So lower version of SSRS might give some design error.

Hi aftab can you help me .

ReplyDeletei have to subtract current month VS Previous month in my matrix. Do you have any idea about this.

Thanks in advance.

Hi,

ReplyDeleteThank you for the article. It was very informative and works a treat.

The only issue I could find in the article was image 6 and 7. The third column should contain both groups.

Instead of having

/----------------------------\

/--------------\

Column 1 Column 2

It should be

/----------------------------\

/----------------------------\

Column 1 Column 2

But thank you very much.

I found this in conjunction with the following article to make the report dynamic an excellent way of creating reports. It took me about 3/4 days to get this working exactly as I wanted but in the end it was worth it. But you do need a bit of time to get your own reports working correctly.

I now have a report with the following:

Year

Week Number

Sales Week 1 - Sales Week 1 Vs Sales Week 1 Last Year - Sales YTD - Sales YTD Vs Sales YTD Last Year - % Up/Down YTD Vs Last Year

Darren

Article: https://www.simple-talk.com/sql/reporting-services/advanced-matrix-reporting-techniques/

ReplyDeleteHere its the simple way you can get your Difference of Two Columns in Matrix report :

ReplyDeleteSum(iif(Fields!Date.Value=Parameters!SelectedDate.Value,Data.Value,Nothing))-Sum(iif(Fields!Rds_Eff_Date.Value=Parameters!PreviousDate.Value,Fields!Data.Value,Nothing))

Mrugesh

Oh my goodness, Mrugesh, my sanity is saved! Thank you thank you thank you: I've been searching and experimenting for over an hour but your post finally gave me the expression needed for the difference between adjacent columns in a tablix group

ReplyDeleteyou are a life saver.

ReplyDeleteAlthough It was not actually what I was looking for but this article is surely a life saver.

ReplyDeleteSince I had to calculate the difference between 2 years (Current and last year) only, I added a column "ColDiff" in the dataset with IF condition as following formula. =IIF(Fields!ColumnName.Value=year(today()),1,-1). Then in the report simply SUM "ColDiff" outside the group.

ReplyDelete