SQLTeam.com | Weblogs | Forums

Creating a % column on Matrix


#1

Hey,

What do you think is the best way to create a column which gives a % based on what's in a matrix?

I have customer down the left, and a yes/no along the top, I then want to add a column that will give how many 'yes's as a % of the total. I tried the following but I know this doesn't work and have finally worked out why:

,(CASE WHEN Roles.Description = 'Yes' THEN 1 ELSE 0 END) / (CASE WHEN Roles.Description = 'Yes' THEN 1 ELSE 1 END) AS [%]

Is it something I should do in the query or in the table (expression)

Thank you!


#2

hi

looking at this 2 things come to mind

please investigate

  1. pivot

  2. sum ( case )

:slight_smile:
:slight_smile:

please let me know if you need anything
thanks


#3

Please provide sample data