Dave's Blog

Business Intelligence: Transforming data into decisions

Default column and rows in matrix

When you’d like to display some columns and rows in a matrix, even though there is no actual data for them, the solution is to add them to the dataset before its processed into the matrix. An easy way to do this is to alter the dataset for the matrix. Use a temporary table and insert the default values into it, then insert the actual data into it et voila:

  

becomes: 

 

As you can see, the second matrix contains a lot more rows Smile! Of course it displays NULL in most cases, but you can easily change NULL into anything else using this expression in the data field:

=IIF(Fields!MatrixData.value IS NOTHING, 0, Fields!MatrixData.value)

The SQL query I used to create a matrix with some default values:

DECLARE @TempTable TABLE

      (

            EyeColor NVARCHAR(50),

            City NVARCHAR(50),

            COUNTNames INT

      )

 

INSERT INTO @TempTable

SELECT EyeColor, City, COUNT(Name) FROM Person GROUP BY EyeColor, City

 

INSERT INTO @TempTable

      VALUES ('Brown', 'Amsterdam', NULL)

INSERT INTO @TempTable

      VALUES ('Blue', 'New York', NULL)

INSERT INTO @TempTable

      VALUES ('Green', 'London', NULL)

INSERT INTO @TempTable

      VALUES ('Grey', 'Miami', NULL)

 

SELECT EyeColor, City, SUM(COUNTNames) AS COUNTNames FROM @TempTable GROUP BY EyeColor, City

As you can see, I used a temporary table. In my case a variable table was suitable, but a table in the TempDB using a CREATE TABLE #TempTable statement is also a solution. The table attributes need to correspond with the attributes in the actual dataset.

Fill the table with the actual data and then with the default values you’d like to see in your columns and rows.

Posted: Dec 16 2007, 09:10 PM by DaveRuijter | with no comments
Filed under:

Comments

No Comments