How to create a percent on a column graph chart? - charts

I have a column graph chart in SSRS 2008 R2 and now I want to display the values as a percent. Currently it just displays the sum totals. My dataset looks like:
people_count facility met_reqs
12 Chattanooga, TN 0
9 Clarksville, TN 0
6 Columbia, TN 0
51 Chattanooga, TN 1
22 Clarksville, TN 1
28 Columbia, TN 1
As you can see, each city has two rows: the first row is the count of persons who did not meet requirements and the second row is for each city which did meet reqs.
Where my last query is:
select
count(distinct people_id) as people_count,
facility,
case when total_los/total_visits *3/7 >= 1 then 1 else 0 end met_reqs
from #final
group by facility, case when total_los/total_visits *3/7 >= 1 then 1 else 0 end
Currently I have this chart to display the sum of people_count for Chart Values, Category Group = facility, and Series Group = met_reqs.
This looks like:
But now for the Y-axis I want this to instead display percentage of persons/facility who met the requirements. How can I do this? So the Y-axis should instead have a range of 0-100%.

Have you considered a 100 % Stacked Column chart?
If you change your existing setup this seems to achieve your requirements:
If this isn't what you're after, can you please update your questions with some more details?
Edit after comment
OK, to meet the specific requirement of displaying % Meeting Requirements only. With the same Dataset, use a Chart type of Column (i.e. the first option) and remove the Series Group:
Change the Values expression to:
=Sum(IIf(Fields!met_reqs.Value = 1, Fields!people_count.Value, Nothing))
/ Sum(Fields!people_count.Value)
i.e. getting the % of total people_count where met_reqs = 1 compared to the total people_count in each group.
For the sake of completeness I changed the number formatting on the Y axis to be percentage.
This looks OK to me:
Hopefully this help get a bit closer to the goal.

Related

Dynamic color format values - Tableau

I want to color format the values (.csv file format) based on the below conditions in tableau desktop.
If consecutive increase of the values or same values with increase values from start Date then values should be Red color .
If Consecutive decrease of the values from startDate then values color should be Green Color
If the values are Increase and then decrease from start date then Yellow.
If the values are decrease then increase then yellow.
For the above data the expected color for the student values should be below..
Student:Mon,Pat,Henry,Kim Yellow,
Jack,stanley Red
Kevin,Lendl -Green
I have tried below code but not working as expected..
Please correct if i missing any thing thing.
//Green - consecutive downward trend
if
window_sum(if FIRST() = 0 then 0
elseif sum([Value]) < lookup(sum([Value]),-1) then 1
end) = MAX([Number of Days]) then "Green"
//Yellow - downward and upward trend but not consecutive
elseif window_sum(if FIRST() = 0 then 0
elseif sum([Value]) < lookup(sum([Value]),-1) then 1
end) > 0 and
window_sum(if FIRST() = 0 then 0
elseif sum([Value]) < lookup(sum([Value]),-1) then 1
end) < MAX([Number of Days]) then "Yellow"
//Red - consecutive upward trend
elseif
window_sum(if FIRST() = 0 then 0
elseif sum([Value]) > lookup(sum([Value]),-1) then 1
end) = MAX([Number of Days]) then "Red"
end
Thanks for your help in advance !!
Without knowing your data structure you can look into table calculations. This may not be straightforward, especially to get the "Compute Using" settings right, but some logic as follows may work.
Calculate the day on day differences (a table calculation will do that).
If the day on day diff is positive then give it a value 1, is negative set it to -1. This would be an IF statement around your table calculation.
Next SUM the result.
Calculate how many dates there are, which will provide the maximum possible number if all are increasing or decreasing every day.
Finally compare the result of the summing if up or down with the maximum possible. This field can sit on the colour shelf.
I haven't tested any of this but, from a logic perspective, you may be able to make this work.
Edit based on comments:
Build the following calculated fields, it should work. You'll be able to troubleshoot calc by calc if having "compute using" challenges. Put the [Colour] field on the colour shelf:
[DailyDiff]: ZN(SUM([Value])) - LOOKUP(ZN(SUM([Value])), -1)
[isUpOrDown]: IF [DailyDiff] >0 THEN 1 ELSEIF [DailyDiff] <0 THEN -1 ELSE 0 END
[TotalUpOrDown]: WINDOW_SUM([isUpOrDown])
[NumDays]: {COUNTD([Date])}-1 //1 less to account for the first day
[Colour]: IF [TotalUpOrDown] = MIN([NumDays]) THEN "Increasing" ELSEIF [TotalUpOrDown]=-MIN([NumDays]) THEN "Decreasing" ELSE "Other" END

Sort Matlab data into groups

I have a column of numerical data (imported from excel) and I would like to sort each of the column entries into 4 different groups based on custom size ranges, then calculate how many column entries are in each group, as a fraction of the total number of entries in the column.
For example, if my column was 1,3,13,11,5,9. I want to calculate how many entries fit into group 1-3, how many fit into group 4-7, and so on. Then calculate the amount of entries in each group as a fraction of the total number of column entries. ie, 6 in this example.
Does anyone know how to do this best?
Thanks
Hannah :)
Sry I misread your question:
here is the updated code
ranges = [1 3
4 7
8 11
12 13];
groups = size(ranges,1);
a = [ 1,3,13,11,5,9];
counter = zeros(groups,1);
for i=1:groups
counter(i) = sum(a>=ranges(i,1) & a<=ranges(i,2));
end
relative_counter = counter / numel(a);
Old answer:
I do not understand how you get your group bounds (in your question the first group has 3 elements and the 2nd group has 4?)
have a look at the following code. (be careful and test how it should behave at group boarders)
groups =4;
a = [ 1,3,13,11,5,9];
range = max(a)-min(a);
rangePerGroup = range/groups;
a_noOffset = a-min(a);
counter = zeros(groups,1);
for i=1:groups
counter(i) = sum(a_noOffset>=rangePerGroup*(i-1) & a_noOffset<=rangePerGroup*i);
end
relative_counter = counter / numel(a);

Conditional formatting in Tableau connected to Cube data

Could someone help me to color these measures on 3 variations - less than 0, equal to 0 and greater than 0. I tried with a calculation
IF [Margin 1] > 0 THEN 1 ELSEIF [Margin 1] < 0 THEN 2 ELSEIF [Margin 1] = 0 THEN 3 END
The reason I have assigned numbers instead of string in the above calculation is, the data is from a cube which will not allow string to be mixed with IF conditon
This is only for Margin 1 while a similar one is also required for Margin 2 and Margin 3 as well. Once I put this calculation to color shelf it colored first value of Margin 1 correctly but at the same time even colors Margin 2 and Margin 3 as well with same shade.
Could someone help to nest color logic calculation for all three Margins so I can have control to choose less than, equal to and greater than 0 in different shades.
Attached is the image of data and tableau sheet of what I have arrived as of now, do let me know for any other details
Not sure how the fact the data is from cube makes much difference, inside of tableau you're looking at a integer and returning a string shouldn't matter.
If you want give this a try
create a calculated field like this:
ZN([Margin 1]) + ZN([Margin 2]) + ZN([Margin 3])
Then create your if statement based on the new calculated field returning string
If [NewCalculated field] <0 then
"Red"
If [NewCalculated field] 0 then
"Amber"
Else
"Green"
End
Have a go

Find the mean of two rows in of a 42 by 4 matrix

I want to find the mean of 1st and 22nd row, the 2nd and 23rd row and so on of a 42-by-4 matrix. The first and 22nd rows are:
0 0 -30 -2.49000000000000
0 0 -30 -2.38000000000000
How can I find the mean of each column in these two rows?
MATLAB has a special syntax for indexing matrices, and you can learn about that by typing
help :
Now, suppose your matrix is
M = randn(42,4); %generating a random matrix with 42 rows and 4 columns
Then you can compute the mean of the desired rows using a simple add and average:
rowmeans = ( M(1:21,:) + M(22:end,:) ) / 2;
which will produce a matrix containing 21 rows and 4 columns, where each row is the desired average.
More generally, for averaging the top half and bottom half of a matrix that has an even number of rows:
rowmeans = ( M(1:end/2,:) + M(end/2+1:end,:) ) / 2;
You might also want to learn about the end keyword in MATLAB:
help end
If you want the mean of each colum of the two rows you can use something like
mean(t([1,22],:));
this will result to
0 0 -30.0000 -2.4350

How to count matches in several matrices?

Making a dichotomous study, I have to count how many times a condition takes place?
The study is based on two kinds of matrices, ones with forecasts and others with analyzed data.
Both in the forecast and analysis matrices, in case a condition is satisfied we add 1 to a counter. This process is repeated for a points distributed in a grid.
Are there any functions in MATLAB that help me with counting or any script that supports this procedure?
Thanks guys!
EDIT:
The case goes about precipitation registered and forecasted. When both exceed a threshold I consider it as a hit. I have Europe divided in several grid points, and I have to count how many times the forecast is correct. I also have 50 forecasts for each year, so the result (hit/no hit) must be a cumulative action.
I've trying with count and sum functions, but they reduce the spatial dimension of the matrices.
It's difficult to tell exactly what you are trying to do but the following may help.
forecasted = [ 40 10 50 0 15];
registered = [ 0 15 30 0 10];
mismatch = abs( forecasted - registered );
maxDelta = 10;
forecastCorrect = mismatch <= maxDelta
totalCorrectForecasts = sum(forecastCorrect)
Results:
forecastCorrect =
0 1 0 1 1
totalCorrectForecasts =
3