Dynamic Columns In Reporting Services Tablix - reporting-services

I have a data query that returns data in the following format:
Name Period Value
-----------------------------
Bob Jan 123
Bob Feb 456
Bob Mar 789
Tom Jan 321
Tom Feb 654
Tom Mar 987
Joe Jan 147
Joe Feb 258
Joe Mar 369
The different periods are constant between names, but will be different between executions of the report (ie, I may query a report on Jan/Feb/Mar now, or Apr/May/Jun later). I'm trying to put that into a table in my Reporting Services report, that would look something like this:
Name Jan Feb Mar
----------------------------
Bob 123 456 789
Tom 321 654 987
Joe 147 258 369
Can anyone point me to an example of doing something like that? I'm not even sure how to describe that 'rotation'(?) of the data. The columns should be dynamic based on what Period values are in the dataset.

Found the answer right after posting. Here's what I did.
Created a new Tablix. Dragged the Name field to the data row of the first column. Dragged the Value column to the data row of the second column. Dragged the Period field to the header row of the second column. That created a new group, and a new second level header column. I then copied the value from that new top header column to the header cell below it, and deleted the whole new header row. When asked whether to delete the row and associated groups, or just row, choose just the row. You should be left with a Row Group and two Column Groups, and it should render as intended.

Related

MySQL - Connect three different tables in transposed fashion

I have three tables:
business:
id name
1 Charlie's Bakery
2 Mark's Pizza
3 Rob's Market
balanco_manual:
id business_id year unit
012 1 2015 ones
123 1 2014 tens
364 2 2014 cents
conta_balanco:
id conta balanco_id valor
412 12.3 012 12324
344 12.5 012 54632
414 14.1 364 344122
789 12 364 2312415
646 12 123 342
I need to combine them all in the business table and make them look like this:
business:
id name 12.3-2015 12.5-2015 11.56-2015 12-2014 2015-unit 2014-unit
1 Charlie's Bakery 12324 54632 NaN 342 ones tens
2 Mark's Pizza NaN NaN NaN 2312415 NaN cents
3 Rob's Market NaN NaN NaN NaN NaN NaN
Explaining a little bit further: the business table has basic registries about the businesses, balanco_manual has yearly information of each one of those businesses and conta_balanco has details of the yearly information in balanco_manual.
Trying to put that last table into words:
- First I need to join business with balanco_manual, combining the "id" column in business with the "business_id" column in balanco_manual. Note that I combine unit and year in one single column named "[year]-unit". Let's call this table "new_business" to make it easir to understand
- After, I need to combine "new_business" with conta_balanco in a similar way we did with the "unit" column. Each "conta" should be combined with the year and become a column "conta-[year]".
I'm quite a beginner with SQL and I'm having interesting difficulties. Could someone help me to crack that out?

SSRS 2 column groups in matrix, 1 row reads from 1, the rest read from the other? (pls help)

Is there a way in SSRS to have an additional row within your row group, to look at a different column group than the rest of the row group
Let's say I have STATES, SALES, MONTH, and BUCKET_MONTH as my dataset fields BUCKET_MONTH is already calculated for me, based off of the MONTH. I want to show something like this:
SAMPLE DATA LIKE THIS FOR FLORIDA (and other months but BUCKET_MONTH only matters for florida let's pretend)
STATE MONTH SALES BUCKET_MONTH
FL JAN 50 FEB
FL FEB 125 FEB
FL MAR 100 MAY
FL APR 0 MAY
FL MAY 100 MAY
SSRS MATRIX MIGHT LOOK LIKE THIS: ?
| 2 groups ?
| MONTH
| BUCKET_MONTH (I can hide this header)
-----------------------------------
1 col group|
STATE | SALES
BUCKET | SALES <-- this row is only visibile for FL which I know how to do
EXPECTED RESULTS WOULD LOOK LIKE THIS
JAN FEB MAR APR MAY JUN JUL
---------------------------------------------------------------------
CA 100 300 150
FL 50 125 100 0 100
FL BUCKET 175 200 <-- BUCKET_MONTH**
MA 0 200 250 50
BUCKET_MONTH in ds shows FEB for the rows with Jan,Feb MONTH, and shows MAY for Mar,Apr, May MONTH
Is there a way to do this in SSRS? Where one of the rows looks at a different column group to establish what column to put the SUM of SALES in?
Much appreciation in advance!
You have to add BUCKET_MONTH as parent column group in your matrix.
Add BUCKET_MONTH in the Column Groups pane, then delete the created row in the matrix selecting Delete groups only option. Now add MONTH as child group in column groups pane.
Add STATE in rows group pane and add a row for bucket total.
Use this expression for BUCKET TOTAL:
=IIF(
Fields!BUCKET_MONTH.Value=Fields!MONTH.Value,
SUM(Fields!SALES.Value,"BUCKET_MONTH"),
Nothing
)
It should produce:
UPDATE: Expression updated taking in account that MONTH and BUCKET_MONTH fields are actually dates.
=IIF(
UCASE(format(Fields!BUCKET_MONTH.Value,"MMMM yy"))=
UCASE(format(Fields!MONTH.Value,"MMMM yy")),
SUM(Fields!SALES.Value,"BUCKET_MONTH"),
Nothing
)
Let me know if this helps.

SSRS - Returning the average where date is 2015

I have been trying to figure this out for a while now and just couldn't find the answer anywhere.
I have a report in SSRS with a column group assigned to "Year", this column expands depending on what parameter the user enters into StartYear. If the user enters "2013" the report will extract all data from 2013 to 2015, this means that there are then 3 columns with the same name ("Cost").
My report looks something like this when entering StartYear as "2013" the value beneath "Year" displays the "Cost" column :
Area | 2013 ("Year") | 2014 ("Year") | 2015 ("Year")
A | 20 | 50 | 25
B | 15 | 65 | 35
C | 40 | 70 | 20
Before the report get built, the reports looks something like this:
Area | [Year]
[Area] | [Cost]
I want to add a column to this report which displays the Average but only for the Year 2015.
This is what I have tried sofar but it brings back the Average for one row and all the year : 20, 50 and 25 instead of 25, 35 and 20:
=Sum(IIF(Fields!Year.Value = 2015, Avg(Fields!Cost.Value), 0))
Any help would be greatly appreciated.
You need an expression like:
=Avg(IIF(Fields!Year.Value = 2015, Fields!Cost.Value, Nothing))
If you are using an IIf expression to get a subset from a DataSet, you must specify Nothing as the False part of the expression, otherwise you just get a bunch of zeroes included in the aggregate, skewing the results.
This assumes the aggregate is running outside any particular Group Scope - you can always add a Scope to the expression to make sure you are checking the entire DataSet:
=Avg(IIF(Fields!Year.Value = 2015, Fields!Cost.Value, Nothing), "DataSet1")
Edit after comment
To expand on the Scope comment above, you can specify the aggregate to run at the Row Group level by adding the Row Group name as a parameter to the expression:
=Avg(IIF(Fields!Year.Value = 2015, Fields!Cost.Value, Nothing), "Area")
Assuming Area is the name of the Row Group.

Reset counter ID to 1 for every new year in MS Access

I have two tables , tblContacts and tblTrackJob. Every time a new record is about to be added in tblContacts , id like to assign its JobNo field to the value of whatever ID is in tblTrackJob has stored. Id like the value to reset to 1 every year.
For example...
first name, last name, JobNo, dateEntered
bob smith 01 1/1/2013
john doe 02 1/2/2013
mary Thomas 03 1/3/2013
Joe Henry 01 1/1/2014
Since we're dealing with Access 2010 we can create a Before Change data macro for the [tblContacts] table to assign the [JobNo] value:
The macro will find the largest [JobNo] in the table from records with a corresponding Year([dateEntered]), and then add 1 to that value to give us the [JobNo] for the new record. If no existing records are found for the corresponding year then the new record gets a [JobNo] equal to 1.

Create Report with dynamic columns

I have SQL Server 2005 Reporting Services. I need to create a report with number of columns that is defined during runtime.
I have a DB table with content like the following:
Person Date Val
----------------------------------------------
Person1 2012-01-03 3
Person2 2012-02-11 5
Person1 2012-02-17 7
Person2 2012-01-19 2
Person2 2012-01-15 4
I have to create a Report like this:
Person Jan 2012 Feb 2012
----------------------------------------------
Person1 3 7
Person2 6 5
In other words, for every Person I have to make sum of all his Value fields for a given month, and put the sum into column corresponding to the month. In the example above I have 6 for Person2 during month Jan 2012 - this is sum of the values 2 (on 2012-01-19) and 4 (on 2012-01-15).
Thus, in design time I do not know the date range covered by that my table. I should detect it, to build array of months covered by the date range (the Jan 2012 and Feb 2012 in the sampel above) and add a column for each of the months.
How should I implement this using SSRS?
In SQL 2008 and later the approach to this problem changed a little bit, so make sure that you are looking at reference materials for 2005 if that is what you are using.
On this page, look for the Matrix section. Matrices in SSRS are designed to solve exactly the problem you describe with minimal effort. In 2008 Matrices and Tables are both variants of the "Tablix:" a control that can have both row and column groups.
If you're stuck with Tablix, here's a similar situation that I have solved, How do i represent an unknown number of columns in SSRS?.