Domain information not available in Tableau - date

I am trying to simply get Quarters within my Tableau run:
Quarter
Role:
Discrete Dimension
Type:
Calculated Field
Contains NULL:
Unknown
Status:
Valid
Formula
if ([VBP_RUN_DT_SHRT_DS]="2019Q1")
then date("03/01/2019")
elseif ([VBP_RUN_DT_SHRT_DS]="2019Q2")
then date("06/01/2019")
elseif ([VBP_RUN_DT_SHRT_DS]="2019Q3")
then date("09/01/2019")
elseif ([VBP_RUN_DT_SHRT_DS]="2019Q4")
then date("12/01/2019")
elseif ([VBP_RUN_DT_SHRT_DS]="2020Q1 2M RO")
then date("3/01/2020")
elseif ([VBP_RUN_DT_SHRT_DS]="2020Q2 2M RO")
then date("6/01/2020")
elseif ([VBP_RUN_DT_SHRT_DS]="2020Q3 2M RO")
then date("9/01/2020")
elseif ([VBP_RUN_DT_SHRT_DS]="2020Q4")
then date("12/01/2020")
elseif ([VBP_RUN_DT_SHRT_DS]="2021Q1 2M RO")
then date("3/01/2021")
end
A query error occurred. Domain information not available.
It seems to be valid before my most recent run adding in Q1 of 2021.
It runs perfectly in other versions of the query.

You could simplify with something like this - or at least by using a case statement
DATETRUNC(‘quarter’, MAKEDATE(INT(LEFT([VBP_RUN_DT_SHRT_DS],4)), INT(MID([VBP_RUN_DT_SHRT_DS],6, 1)) * 3, 1))
Assuming your data source supports the MAKEDATE() function. If not, you could create something similar using DATE() or DATEPARSE()

Related

Why do I get NA values after filtering a dataset and running a regression based on that set?

I am using the gpa1 dataset in R and am trying to filter out all instances where a student has worked less than or equal to 19 hours and does not volunteer or participate in any clubs. I can run the filter and save the data fine, and get the results I want (job19=1, clubs=0, and voluntr=0, but when I try to run a regression based on the new dataset the job19 values just come up as "NA"
This is the code that I used:
PTjob19 <- filter(gpa1, job19 == 1, voluntr == 0, clubs == 0)
View(PTjob19)
olsreg9 <- lm(colGPA~job19 + age + male + hsGPA + ACT + siblings + skipped + fathcoll + mothcoll, data=PTjob19)
I expected that job19 would have some kind of value be it negative or positive, but the values were just listed as "NA." Cam someone please help?
So I figured this out. The reason I was getting an "NA" value was that I wasn't giving R anything to compare. I was trying to run a regression where people only worked less than 20 jobs, which of course R couldn't give me stats on.

Tableau mixing aggregate and non-aggregate results error

I have a problem creating a calculated field in Tableau. I have data like so:
ID ... Status Step1 Step2 Step3
1 ... Accepted 1 1 1
2 ... Waiting 1 0 0
3 ... Discard 0 0 0
4 ... Waiting 1 1 0
...
I would like to create a calculated column that will give me the name of the last Step, but only when status is 'Accepted'. Otherwise I want the status. The syntax is quite easy, it looks like this:
IF [Status] = 'Accepted' THEN (
IF [Step3] = 1 THEN 'Step3' ELSEIF [STEP2] = 1 THEN 'Step2' ELSEIF [STEP1] = '1' THEN 'Step1' ELSE 'Step0')
ELSE [Status]
The problem is that the column 'Status' is a Dimension and the 'Step' statuses come from Measure. So they are AGG(Step1), AGG(Step2),...
I guess that is the reason I get this error:
Cannot mix aggregate and non-aggregate comparisons or results in 'IF' expressions.
I am not very familiar with Tableau. Any idea how I can solve this?
Solution:
Just use function ATTR that will make the non-aggregate function (Status) into an aggregate one. Then it is possible to combine them and the calculation is working.
IF ATTR([Status]) = 'Accepted' THEN (
IF [Step3] = 1 THEN 'Step3' ELSEIF [STEP2] = 1 THEN 'Step2' ELSEIF [STEP1] = '1' THEN 'Step1' ELSE 'Step0')
ELSE ATTR([Status])
Tableau automatically interprets numeric values as measures. It appears though that in your case they are a boolean (0 for false, 1 for true) and really ought to be dimensions.
Convert Step 1, Step 2, and Step 3 to dimensions. Highlight the fields, right click, and choose Convert to Dimension.

Tableau - Bins based on Fixed LOD Customer Units

What I'm trying to do: Create a histogram showing the distribution of customers based on their annual ordering size (1-10 units, 11-50, and so on) based on a Combined Field (Child + Zip Code which is our definition of a customer).
Problem: I cannot figure out a way to calculate the different bins correctly. I've seen plenty of posts for using bins in Tableau but none calculated based off a unique id like mine. It seems the customers are being put in every category (1-10, 11-20, etc...) instead of a unique category if their unit sales go beyond the <= . Perhaps I'm misunderstanding FIXED LOD calcs.
End goal: Get a count of the customers in these different ordering ranges to display on a histogram.
Having no luck with this formula:
IF { FIXED [UID_Cust] : SUM([Units]) } <= 10 THEN '1-10'
ELSEIF { FIXED [UID_Cust] : SUM([Units]) } <= 20 THEN '11-20'
ELSEIF { FIXED [UID_Cust] : SUM([Units]) } <= 50 THEN '21-50'
ELSEIF { FIXED [UID_Cust] : SUM([Units]) } <= 250 THEN '51-250'
ELSE '>250'
END
Here is a picture of what I'm currently getting. Everything would be perfect if I could replace those little blocks with just one number, the count of the customers in that range.
Turns out the problem was the LOD calc. I needed to add the year since I forgot Fixed LOD ignores worksheet filters.
{ FIXED [UID_Cust], [Order_Date] = 2017 : SUM([Units]) }
Then I saved this as an individual table calc "UID_Sales"
IF [UID_Sales] <= 10 THEN '1-10'
ELSEIF [UID_Sales] <= 20 THEN '11-20'
ELSEIF [UID_Sales] <= 50 THEN '21-50'
ELSEIF [UID_Sales] <= 250 THEN '51-250'
ELSE '>250'
END

Incremental increase of a variable over time

I am usually programming in Python, but for an assignment, I am using Simulink. I am wondering why the above elseif ladder does not generate an incremental increase of the variable [IP3] over time. What I would think it should do is return 0.01 until t = 500, then 0.03 until t = 1000, then 0.1 until 1500, 1 until 2000, and 10 from then on. Apologies for the older image btw, I updated the variables in the mean time.
In the Simulink model that you showed, elseif parts will never execute since:
if u1>0 is satisfied, none of the other conditions will be checked and thus it will always be returning 0.01 for all u1>0.
And when u1<=0, all the conditions will be checked but none of them
will be satisfied. (u1 may never be less than zero in your case as u1 is time).
This behavior is same in every programming language.
Fixing your If-elseif Statements:
You need to add this in the If block:
Under If expression (e.g. u1 ~= 0), write this:
u1>0 & u1<=500
Under Elseif expressions (comma-separated list, e.g. u2 ~= 0, u3(2) < u2):, write this:
u1>500 & u1<=1000, u1>1000 & u1<=1500, u1>1500 & u1<=2000, u1>2000
Since u1 is time in your case which cannot be negative, you may also want to use the else part. So instead of the last step you can also do this:
Under Elseif expressions (comma-separated list, e.g. u2 ~= 0, u3(2) < u2):, write this:
u1>500 & u1<=1000, u1>1000 & u1<=1500, u1>1500 & u1<=2000
and connect the output of the else part which was connected with the output of u1>2000 before.

How to join a string and float value in a calculated field using Tableau?

I am trying to create a calculated field where the output is "x% Over the Goal", however cannot due to string and float values. Essentially, what I want is the following:
IF Actuals > Goal THEN Actuals/Goal+'Over Goal'
ELSEIF Actuals < Goal then Actuals/Goal+'Under Goal'
ELSE 'At Goal' END
Is something like this possible? I've tried creating two separate calculated fields and concatenating them, but that does not work either.
Any help would be greatly appreciated.
You Can achieve this in a single calculated field:
IF [Actuals] > [Goal] THEN STR(FLOAT([Actuals] / [Goal])) + "Over Goal"
ELSEIF [Actuals] < [Goal] THEN STR(FLOAT([Actuals] / [Goal])) + "Under Goal"
ELSE "At Goal" END