SSRS 2005 - Custom Quarters in a Matrix report
I created a matrix that the Quarters of our budget are:
Q1 7/1/2010 through 9/30/2010;
Q2 10/1/2010 through 12/31/2010,
Q3 1/1/2011 through 3/31/2011,
Q4 4/1/2011 through 6/30/2011.
In my query I created a column Quarters: DATEPART(q, DateRecd), this is grouping the quarters starting in January the first Quarter, so in the header of the column I created this expression:
="Q" & iif(Fields!Quarter.Value = 1, 3,iif(Fields!Quarter.Value = 2, 4,iif(Fields!Quarter.Value = 3, 1,iif(Fields!Quarter.Value = 4, 2,""))))
Now the Quarters are displaying the data like Q4, Q3, Q1, Q2.
My questions how can display the data as Q1, q2, Q3, Q4?
Thanks,
AngieAngie Rivera
March 15th, 2011 7:43pm
Hi Angie,
From you description, I noticed that you need to change the Quarter values form Q1,Q2,Q3,Q4 to Q3,Q4,Q1,Q2. In order to achieve this, I would suggest you modify the dataset query
at first.
For example, if the original query is like
SELECT C1, C2, DATEPART(q, DateRecd) as ‘Quarter’ FROM Table1, please change it to
SELECT C1, C2,
'Q'+Convert(CHAR(1),(DATEPART(q, DateRecd)+2)% 4) as 'Quarter'
FROM Table1
After that, we will get the expected quarter value from the dataset directly. Then, we need to sort the column group by the Quarter field, please refer to the steps below:
1.
Right click the handle of the matrix, select Properties.
2.
In the Matrix Properties window, select the Groups tab.
3.
Select the Quarter group in the Columns list and click Edit…
4.
In the Grouping and Sorting Properties window, select the Sorting tab.
5.
Specify =Fields!Quarter.Value in the Expression column and select Ascending in the Direction column.
Thanks,
Tony ChainTony Chain [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Free Windows Admin Tool Kit Click here and download it now
March 16th, 2011 6:28pm
Hi,
go to colum grouping select Group on add expression =DATEPART(q, DateRecd)
then go to sorting select expression add= DATEPART(q, DateRecd) change order to ZtoA.
it is working for me.
if it is not working check your date valus contain any null values or default values in database.
filter it.Best Regards, C.Gnanadurai ----------------------- Please mark the post as answer if it is helpfull to you
March 16th, 2011 7:10pm
Gnanadurai:
When you filter by expression =DATEPART(q, DateRecd) in descending order, you get Q1, Q2, Q3, Q4, but this is base on calendar quater year. My Quarters start like this:
Q1 = 7/1/2010 through 9/30/2010; in a Calendar year my Quarter Q1 belongs to Q3
Q2 = 10/1/2010 through 12/31/2010, in a Calendar year my Quarter Q2 belongs to Q4
Q3 = 1/1/2011 through 3/31/2011, in a Calendar year my Quarter Q1 belongs to Q1
Q4 = 4/1/2011 through 6/30/2011, in a Calendar year my Quarter Q1 belongs to Q2
So, if I sort in the datepart expression it will be base in regular calendar year quarters.
Any other suggestion, PLEASE!!Angie Rivera
Free Windows Admin Tool Kit Click here and download it now
March 16th, 2011 7:55pm
Tony:
I tried this but I am getting a Q0, Q1, Q2, Q3. Q0 = to all the application received in the 4th quarter. I explained if I enter the following date range >=7/1/2009 and <=6/30/2010. Q0 is showing all the applications that were received
between 4/1/2010 and 6/30/2010. How can fix this. Below is my query
SELECT ItemID, 'Q' + CONVERT(CHAR(1), (DATEPART(q, DateRecd) + 2) % 4) AS Quarter, CompDate, DateRecd, PK_ZEDaCTN
FROM dbo.tblZEDActn
GROUP BY ItemID, DATEPART(q, DateRecd), CompDate, DateRecd, PK_ZEDaCTN, 'Q' + CONVERT(CHAR(1), (DATEPART(q, DateRecd) + 2) % 4)
HAVING (DateRecd >= @StartDate) AND (DateRecd <= @EndDate) AND (ItemID <> N'IA') AND (ItemID <> N'SPT') AND (ItemID <> N'VCT')
ORDER BY 'Q' + CONVERT(CHAR(1), (DATEPART(q, DateRecd) + 2) % 4), ItemIDAngie Rivera
March 16th, 2011 10:26pm
Hi Angie,
As you pointed out, I made a mistake by using the % operator in the query. I apologize for it. In order to fix this, please modify the query like the following one
SELECT
ItemID,
CASE DATEPART(q, DateRecd)
WHEN 1 THEN 3
WHEN 2 THEN 4
WHEN 3 THEN 1
WHEN 4 THEN 2
END as 'Quarter'
CompDate, DateRecd, PK_ZEDaCTN
FROM Sales.SalesOrderHeader
Please also apply the CASE expression in GROUP BY and ORDER BY clauses as needed.
Thanks,
Tony ChainTony Chain [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Free Windows Admin Tool Kit Click here and download it now
March 19th, 2011 3:14am
Tony:
Thanks a lot, it works great!!
AngieAngie Rivera
March 19th, 2011 5:00am