Tableau Sorting Stacked Bar Chart - tableau-api

I am trying to create a stacked bar chart of different diseases. Each bar should contain the disease's respective year (4 bars per disease). However, I am getting the total disease count rather than the count by year. I created a "Choose a Disease" parameter and a calculated field "p. Disease"
p. Disease:
CASE [Choose a Disease]
WHEN 1 then SUM([Hemolytic uremic snydrome post-diarrheal, Cum 2020†] + [Hemolytic uremic snydrome post-diarrheal, Cum 2021†] + [Hemolytic uremic snydrome post-diarrheal, Current week] + [Hemolytic uremic snydrome post-diarrheal, Previous 52 weeks Max†])
WHEN 2 then SUM([Hepatitis A, acute, Cum 2020†] + [Hepatitis A, acute, Cum 2021†] + [Hepatitis A, acute, Current week] + [Hepatitis A, acute, Previous 52 weeks Max†])
WHEN 3 then SUM([Hepatitis B, acute, Cum 2020†] + [Hepatitis B, acute, Cum 2021†] + [Hepatitis B, acute, Current week] + [Hepatitis B, acute, Previous 52 weeks Max†])
END
Is there something I could do to fix this? Thanks.

Related

Plotting ATR as hline

i want two horizontal lines on chart with marks day highest and lowest according to ATR.
Let’s say ATR (14) is 1$ and market opens at 10$.
So, one line at day highest 11$ (market open + ATR -> 10$ + 1$)
Other line at day lowest 9$ (market open – ATR -> 10$ - 1$)
If I use plot(l_atr') it works, but if I use hline I get an error: line 13: Cannot call 'hline' with argument 'price'='l_atr'. An argument of 'series float' type was used but a 'input float' is expected.
I’m not sure what it means with “input float”.
How can I fix this?
//#version=5
indicator("Arego ATR", overlay=true)
o = request.security("", "D", open, lookahead=barmerge.lookahead_on)
atr = request.security("", "D", ta.atr(14))
l = request.security("", "D", low, lookahead=barmerge.lookahead_on)
h = request.security("", "D", high, lookahead=barmerge.lookahead_on)
l_atr = o + (h - o) - atr
h_atr = o + (l - o) + atr
hline(l_atr)
//plot(h_atr)
//plot(l_atr)

Functions with pre millenium dates in q

I've built a function in q such that I can see how many Sunday's fall on the 1st of the month between two dates
\W 1 f3:{[sd;ed] count distinct `week$(sd + til 1 + ed - sd) where (`dd$distinct `week$sd + til 1 + ed - sd)=01}
How can I edit with to work with pre 2000 dates? Can I put a modulus around the negative dates? Or will that redender my function incorrect?
You can also try this:
q) f:{sum 1=mod[`date$a[1] + til 1+(-). a:(0;1<`dd$x)+`month$(y;x);7]}
q) f[2018.01.01;2018.12.31] / 2
q) f[1998.01.02;1999.12.31] / 4

q/KDB - nprev function to get all the previous n elements

I am struggling to write a nprev function in KDB; xprev function returns the nth element but I need all the prev n elements relative to the current element.
q)t:([] i:1+til 26; s:.Q.a)
q)update xp:xprev[3;]s,p:prev s from t
Any help is greatly appreciated.
You can achieve the desired result by applying prev repeatedly and flipping the result
q)n:3
q)select flip 1_prev\[n;s] from t
s
-----
" "
"a "
"ba "
"cba"
"dcb"
"edc"
..
If n is much smaller than the rows count, this will be faster than some of the more straightforward solutions.
The xprev function basically looks like this :
xprev1:{y til[count y]-x} //readable xprev
We can tweak it to get all n elements
nprev:{y til[count y]-\:1+til x}
using nprev in the query
q)update np: nprev[3;s] , xp1:xprev1[3;s] , xp: xprev[3;s], p:prev[s] from t
i s np xp1 xp p
-------------------
1 a " "
2 b "a " a
3 c "ba " b
4 d "cba" a a c
5 e "dcb" b b d
6 f "edc" c c e
k equivalent of nprev
k)nprev:{$[0h>#y;'`rank;y(!#y)-\:1+!x]}
and similarly nnext would look like
k)nnext:{$[0h>#y;'`rank;y(!#y)+\:1+!x]}

Get a^ib^jc^k from expand (a+b+c)^n

I want to write a function func(n) get a^ib^jc^k from expand (a+b+c)^n.
Example :
When n = 1 then (a + b + c)^1 = a + b + c and func(n) return {a, b, c}.
When n = 2 then (a + b + c)^2 = a^2 + b^2 + c^2 + 2ab + 2bc + 2ca and func(n) return {a^2, b^2, c^2, ab, bc, ca}.
I have solution using three loops but in think it's not nice, someone can help me. Thanks you very much.
In maple to do some sort of programming you can use proc short for procedure.
restart:
ftn:= proc(n)
expand((a+b+c)^n);
{op(%)};
end;
Now let's try to check whether we get what you want.
ftn(1);
{a, b, c}
ftn(2);
{a^2, b^2, c^2, 2*a*b, 2*a*c, 2*b*c}
If you do not want the constant coefficients of ab, ac and bc then you can do this
restart:
ftn:= proc(n)
expand((a+b+c)^n);
convert([coeffs(%,[a,b,c],'powers')],array):
convert({powers},list);
end;
ftn(2);
[a^2, b^2, c^2, ab, ac, b*c]

Crystal Reports Cross-tab with mix of Sum, Percentages and Computed values

Being new to crystal, I am unable to figure out how to compute rows 3 and 4 below.
Rows 1 and 2 are simple percentages of the sum of the data.
Row 3 is a computed value (see below.)
Row 4 is a sum of the data points (NOT a percentage as in row 1 and row 2)
Can someone give me some pointers on how to generate the display as below.
My data:
2010/01/01 A 10
2010/01/01 B 20
2010/01/01 C 30
2010/02/01 A 40
2010/02/01 B 50
2010/02/01 C 60
2010/03/01 A 70
2010/03/01 B 80
2010/03/01 C 90
I want to display
2010/01/01 2010/02/01 2010/03/01
========== ========== ==========
[ B/(A + B + C) ] 20/60 50/150 80/240 <=== percentage of sum
[ C/(A + B + C) ] 30/60 60/150 90/240 <=== percentage of sum
[ 1 - A/(A + B + C) ] 1 - 10/60 1 - 40/150 1 - 70/240 <=== computed
[ (A + B + C) ] 60 150 250 <=== sum
Assuming you are using a SQL data source, I suggest deriving each of the output rows' values (ie. [B/(A + B + C)], [C/(A + B + C)], [1 - A/(A + B + C)] and [(A + B + C)]) per date in the SQL query, then using Crystal's crosstab feature to pivot them into the output format desired.
Crystal's crosstabs aren't particularly suited to deriving different calculations on different rows of output.