Quantcast
Channel: SQL Server Reporting Services, Power View forum
Viewing all articles
Browse latest Browse all 10045

Colour Formatting Based on Conditions

$
0
0

I have an issue in trying to format rows base on conditions. Below is a replication of the tables and the select statement.

CREATE TABLE #CompareVal
(CompareValID  INT          Not Null
, ValName      NVARCHAR(75) Null
, Vehicle      INT          Null
, Driver       INT          Null
);
GO

INSERT INTO #CompareVal(CompareValID, ValName, Vehicle, Driver)
VALUES(1,'ABC Company Value',10, 15)

SELECT * FROM #CompareVal


CREATE TABLE #GroupStatistic
(StatisticID      INT          IDENTITY(1,1)
, CompanyName     NVARCHAR(75) Null
, [Description]   NVARCHAR(75) Null
, VehicleAvalible INT          Null
, DriverAvailable INT          Null
);

INSERT INTO #GroupStatistic(CompanyName, [Description], VehicleAvalible, DriverAvailable)
VALUES ('APC and Sons', 'Something..', 5, 7)
     , ('ABC Camp limited', 'We deliver..', 15, 15)
	 , ('Silas and Sons', 'Anything goes.', 10, 7)
	 , ('Richard and Co', 'Helping you all the way.', Null, Null)
	 , ('Kayla and Jane', '', 0, 3)
	 , ('James and Jane', '', 1, 0)

SELECT * FROM #GroupStatistic

SELECT CompanyName
     , [Description]
	 , ISNULL(CAST(VehicleAvalible AS NVARCHAR(30)),'N/A') AS VehicleAvalible
	 , ISNULL(CAST(DriverAvailable AS NVARCHAR(30)),'No Driver available') AS DriverAvailable
FROM #GroupStatistic

  UNION

SELECT '' AS CompanyName
     , 'Group Value Standard' AS [Description]
	 , CAST(Vehicle AS NVARCHAR(30)) AS VehicleAvalible
	 , CAST(Driver AS NVARCHAR(30)) AS DriverAvailable
FROM #CompareVal


DROP TABLE #GroupStatistic
DROP TABLE #CompareVal

 

  1. First issue, James and Jane does not have a driver available and that should show "No Driver available"
  2. I am to compare values in VehicleAvailable and DriverAvailable to the first row - (Group Value Standard row) so that when a value is less than the value in first row, it should be Gold, if equal to, Blue and if greater than then, Red.
  3. The first row is to be Black

In other for me to be able to compare, I added columns like so:

SELECT #CompanyName
     , [Description]
	 , ISNULL(CAST(VehicleAvalible AS NVARCHAR(30)),'N/A') AS VehicleAvalible
	 , ISNULL(CAST(DriverAvailable AS NVARCHAR(30)),'No Driver available') AS DriverAvailable
	 , 0 AS TotalVehicles
	 , 0 AS TotalDrivers
FROM GroupStatistic

  UNION

SELECT '' AS CompanyName
     , 'Group Value Standard' AS [Description]
	 , CAST(Vehicle AS NVARCHAR(30)) AS VehicleAvalible
	 , CAST(Driver AS NVARCHAR(30)) AS DriverAvailable
	 , Vehicle
	 , Driver
FROM #CompareVal


And my expression for "VehicleAvailable" column is :

=Switch(Fields!Description.Value = "Group Value Standard" AND Fields!VehicleAvalible.Value = Fields!TotalVehicles.Value, "Black" , Fields!Description.Value = "Group Value Standard" AND Fields!VehicleAvalible.Value < Fields!TotalVehicles.Value, "Black" , Fields!Description.Value = "Group Value Standard" AND Fields!VehicleAvalible.Value > Fields!TotalVehicles.Value, "Black" , Fields!Description.Value <> "Group Value Standard" AND Fields!VehicleAvalible.Value < Fields!TotalVehicles.Value, "Gold" , Fields!Description.Value <> "Group Value Standard" AND Fields!VehicleAvalible.Value > Fields!TotalVehicles.Value, "Red" , Fields!Description.Value = "Group Value Standard" AND Fields!VehicleAvalible.Value = Fields!TotalVehicles.Value, "Blue" )

This doesn't work as I am comparing integer against text value. How do I format to get result like the below image?

Thank you


Zionlite



Viewing all articles
Browse latest Browse all 10045

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>