Expected 'End' to match 'if' at character 0? - data-visualization

IF AVG([Covid Death Rate Cleaned]) >= 275 THEN "Extremely high COVID death rate"
ELSEIF AVG([Covid Death Rate Cleaned]) >= 226.3 THEN "High COVID death rate"
ELSEIF AVG([Covid Death Rate Cleaned]) <= 200 THEN "Low COVID death rate"
ELSE AVG([Covid Death Rate Cleaned]) <= 175 THEN "Extremely low COVID death rate"
END
This code is giving the an error. Not sure what is wrong. It gives me the error "Expected 'End' to match 'if' at character 0." This is in Tableau by the way, I am trying to make a KPI for data.

Your ELSE should be ELSEIF. Or you should remove the AVG([Covid Death Rate Cleaned]) <= 175 THEN, which only makes sense with an ELSEIF, not an ELSE.

ELSE should cater to all remaining unsatisfied conditions so it should not be limited to specific conditions as you would ELSEIF.
So to get rid of the error your code should look like this if you want to use ELSE:
IF AVG([Covid Death Rate Cleaned]) >= 275 THEN "Extremely high COVID death rate"
ELSEIF AVG([Covid Death Rate Cleaned]) >= 226.3 THEN "High COVID death rate"
ELSEIF AVG([Covid Death Rate Cleaned]) <= 200 THEN "Low COVID death rate"
**ELSE** "Extremely low COVID death rate"
END
##OR else you could use ELSEIF if you must specify the condition:
IF AVG([Covid Death Rate Cleaned]) >= 275 THEN "Extremely high COVID death rate"
ELSEIF AVG([Covid Death Rate Cleaned]) >= 226.3 THEN "High COVID death rate"
ELSEIF AVG([Covid Death Rate Cleaned]) <= 200 THEN "Low COVID death rate"
**ELSEIF** AVG([Covid Death Rate Cleaned]) <= 175 THEN "Extremely low COVID death rate"
END

Related

How to find first day of multi-day event on monthly basis?

I have a table with daily snapshot data that has a date and amount column. I'm converting this to a monthly snapshot table. Every record in this monthly table should look like what you see in the table below at 31-01.
If on the last day of the month the amount is negative, amount_negative_lastday_of_month = True. The part I can't figure out is the first_date_negative_amount. If the amount_negative_lastday_of_month = True, I want to get the first day on which the amount became negative for that specific period where the amount was negative. In the table below that would be 28-01-2021.
If this period of amount < 0 continuous on until the end of February, we will see the exact same in the Feb. monthly snapshot where amount_negative_lastday_of_month = True and amount_negative_lastday_of_month = 28-01-2021.
If this period of negative amount is over, and in a few months a new period of negative amount begins, I want to do the same again.
The problem is that I can't figure out how to group/window my data by varying periods of time where a certain condition is met (amount < 0).
How can I query this?
date
amount
last_day_of_month
amount_negative_lastday
first_date_negative_amount
26-1-2021
-10
27-1-2021
200
28-1-2021
-200
29-1-2021
-200
30-1-2021
-200
31-1-2021
-100
31-1-2021
TRUE
28-1-2021
1-2-2021
-122
2-2-2021
-222
3-2-2021
-322

Query date and specific time in the where clause 3

How can I get 3rd shift data from the where clause. I'm using current date, but even with what I don't get any resutls. I'm looking to see 3rd shift sale from time range 9pm to 5am ( Next Day ).
SELECT WORK_CENTER, SUM(SALES) AS SALES
FROM ZME_SALES
WHERE DATE_TIME_START >=sys_extract_utc(cast(trunc(current_date) + 21/24 as time stamp with time zone))
AND DATE_TIME_START < sys_extract_utc(cast(trunc(current_date)+1 + 5/24 as timestamp with time zone))
Here's my expected results.
SHIFT WORK_CENTER SALES
SHIFT-3 8001 1524
SHIFT-3 8002 1347
SHIFT-3 8003 1201
SHIFT-3 8004 1146

Forecast based on monthly figures

I receive a monthly list of unpresented cheques with payment date. Those reached certain age in Month1 (say, 90 days to date) are recognized as overdue and counted as X(1).
Those of > 60 days age Y(1) are near-overdue and will appear in Month2 statement as X(2), if not banked by then.
Some of cheques arу pretty old and reside in the system for ages (over 1000 days), and therefore appear in each X monthly statement, while certain share of cheques in both X(n) and Y(n) will disappear from next month's X(n+1).
What would be the best logic for next month forecast basing on actual historical data? The most importand is X, but Y also welcome. It should be a forecast, as there is no next month's data as of yet.
The data is in SQL if it is relevant, but I need to understand the logic most, then I can generate code.
The logic below gets you the Number of Checks, Percent Overdue, Percent Near Overdue, and Percent All Other Checks counts for the current time period. Next step would be to create a query that does this for 3 or 12 months (or however many months you want to use to get projections). Then you trend out your total number of checks, and trend the percentages for each of the subcategories. You can use that to predict future amounts.
SELECT
Count(*) AS Number of Checks,
(SUM(CASE WHEN s.ageofcheck >= 90 THEN 1 ELSE 0 END))/Count(*) AS Number of Checks AS Percent Overdue Checks,
(SUM(CASE WHEN s.ageofcheck >= 60 AND s.ageofcheck < 90 THEN 1 ELSE 0 END))/Count(*) AS Number of Checks AS Percent Near Overdue Checks,
(SUM(CASE WHEN s.ageofcheck < 60 THEN 1 ELSE 0 END))/Count(*) AS Number of Checks AS Percent All Other Checks
FROM
(
SELECT
c.checknumber,
DATEDIFF(dd,GETDATE(),c.checkdate) AS ageofcheck
FROM
checks_table AS c
) AS s

How to get cases to work

I am trying to answer a question in which I have to use cases in visual basic.
The question is:
Write a program that asks the user for the number of hours worked this week and their hourly rate of pay. The program is to calculate the grass pay. If the number of hours worked is greater than 40, the extra hours are paid at 1.5 times the rate. The program should display an error message if the number of hours worked is not in the range 0 to 60.
Here is the code I wrote, any ideas on what went wrong would be greatly appreciated.
Console.WriteLine("This will calculate the gross profit from the hours you work and the hourly pay")
Console.WriteLine("Your work hours can not be under 0 or above 60,
if you work above 40 hours the extra hours will be 1.5 times the original")
Console.Write("Please enter the hours you work a week: ")
Dim hours As Integer = Console.ReadLine()
Console.Write("Please enter the hourly pay you get: ")
Dim hourlyPay As Decimal = Console.ReadLine()
Dim message As String = "Your gross pay per week is: £"
Dim weeklyPay As Decimal
Select Case hours
Case 0 < hours < 40
weeklyPay = hours * hourlyPay
Case hours > 40 And hours < 60
weeklypay = ((40 * hourlyPay) + ((hours - 40) * (hourlyPay * 1.5)))
Case hours < 0 Or hours > 60
message = "Sorry the hours you entered are above the range try again"
End Select
Console.WriteLine(message & weeklyPay.ToString("N2"))
Console.ReadLine()
Select works on a first come first served basis, by testing for conditions and handling them in order you can eliminate each condition so that all that remains is the 'default' condition.
Select Case hours
Case Is > 60
message = "Sorry the hours you entered are above the range try again"
Case Is < 0
message = "Sorry the hours you entered are below the range try again"
Case Is > 40
weeklypay = ((40 * hourlyPay) + ((hours - 40) * (hourlyPay * 1.5)))
Case Else
weeklyPay = hours * hourlyPay
End Select
MSDN - Select...Case Statement (Visual Basic)
I figured out how to solve it:
Console.WriteLine("This will calculate the gross profit from the hours you work and the hourly pay") 'sends the message of what this program does
Console.WriteLine("Your work hours can not be under 0 or above 60,
if you work above 40 hours the extra hours will be 1.5 times the original") 'explains the boundaries and conditions
Console.ReadLine()
Console.Write("Please enter the hours you work a week: ") 'asks for the hours worked
Dim hours As Integer = Console.ReadLine() 'declares hours as an integer and sets it's value for what the user enters
Console.Write("Please enter the hourly rate of pay: ") 'asks for the hourly rate of pay
Dim hourlyPay As Decimal = Console.ReadLine() 'declares hourlyPay as a decimal and sets it's value for what the user enters
Dim message As String = "Your gross pay per week is: £" 'declares message as a string and sets it's value to tell the user what their pay is - this will be useful later
Dim weeklyPay As Decimal 'declares weekly pay as a decimal
Select Case hours 'An if statement would complicated to use so, i used a select case
Case 0 To 40 'when hours are between 0 and 40, then the weekly pay is normal (hourly rate * hours)
weeklyPay = hours * hourlyPay
Case 40 To 60 'however when hours are above 40, then the extra hours (hours - 40) are paid at a higher rate (1.5 times)
weeklyPay = ((40 * hourlyPay) + ((hours - 40) * (hourlyPay * 1.5)))
Case < 0 'when hours are under the boundary of 0 then send the error message
message = "Sorry the hours you entered are under the range try again "
Case > 60 'when hours are over the boundary of 60 then send the error message
message = "Sorry the hours you entered are above the range try again "
End Select
Console.WriteLine(message & weeklyPay.ToString("N2")) 'this sends the message across to the user and their pay
Console.ReadLine() 'stops the program from terminating

iTunesConnect, Sales and Trends, Units

Are units in iTunesConnect Sales and Trends report aggregated over all time? For example, if I show 100 units one week and 150 units the next week, do I have 250 downloads for all time or just 150 for all time? If it's the latter, what explains a decrease in units? Uninstalls?
Thanks!