I am trying to create sum() expression which will summarize rows and place results into "Total Servers in TPM" column. Looks like I am not able to provide the right feed for sum expression.
SSRS matrix report in design mode looks like:
[TPM_scan_type] expression can have 2 values:
"TPM Succesfull Scan" or
"TPM Failed Scan"
=Switch(Fields!ScanStatus.Value = "OK","TPM Succesfull Scan",Fields!ScanStatus.Value = "FAILED!","TPM Failed Scan")
[scan_count] expression just aggregate values for each "Primary SA"
=Switch(Fields!ScanStatus.Value="FAILED!",Count(Fields!ScanStatus.Value),Fields!ScanStatus.Value="OK", CountDistinct(Fields!ServerName.Value))
Results:
Data sample:
USE tempdb;
GO
IF OBJECT_ID('dbo.TPM_test') IS NOT NULL
DROP TABLE dbo.TPM_test;
GO
CREATE TABLE dbo.TPM_test
(
ServerName varchar(30) NOT NULL,
ScanStatus varchar(10) NOT NULL,
Primary_SA varchar(30) NOT NULL,
HotfixID int
);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('LDNSQLF700', 'OK', 'SA1', 157848);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('LDNSQLF700', 'OK', 'SA1', 976832);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('LDNSQLF700', 'OK', 'SA1', 234354);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('NYSQL502', 'FAILED!', 'SA1', '');
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('PSQL1011', 'FAILED!', 'SA1', '');
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('NTQDF002', 'OK', 'SA1', 878641);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('AUSSQL140', 'OK', 'SA2', 537990);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('AUSSQL140', 'OK', 'SA2', 1349605);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('JAP543X2', 'FAILED!', 'SA2', '');
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('EU456CLX', 'FAILED!', 'SA2', '');
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('EUCTX654', 'OK', 'SA2', 5637965);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('EUCTX654', 'OK', 'SA2', 6464367) ;
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('EUCTX654', 'OK', 'SA2', 1323123) ;
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('EUCTX654', 'OK', 'SA2', 1004326) ;
GO