I'm working on a covid dashboard for my community: Chestertown Responds My challenge is to compute the 7-day moving average and displaying that information on the Google Studios page.
I've managed to do the calculation via Bigquery (though it might not be as efficient as if could be -- apologies) with the following code:
--Declare some variables. declare ConfirmedCases numeric; declare DateOfAverage datetime; Declare mvgAvg numeric; declare caseDiff numeric; declare multiplier numeric;
--get/set confirmed cases set ConfirmedCases = (select covid.confirmed_cases FROM
bigquery-public-data.covid19_usafacts.summary
AS covid WHERE
county_fips_code = '24029' ORDER BY date DESC limit 1);--get/set the latest date. set DateOfAverage = (select Date FROM
bigquery-public-data.covid19_usafacts.summary
AS covid WHERE
county_fips_code = '24029' ORDER BY date DESC limit 1); --get/set 7 day average set mvgAVG = (select avg(Covid.confirmed_cases) over(order by Covid.confirmed_cases asc ROWS 7 PRECEDING) FROMbigquery-public-data.covid19_usafacts.summary
AS covid WHERE
county_fips_code = '24029' ORDER BY date DESC limit 1);
--calculate the difference between actual and average. set caseDiff = (select avg(Covid.confirmed_cases) over(order by Covid.confirmed_cases asc ROWS 7 PRECEDING) - covid.Confirmed_cases frombigquery-public-data.covid19_usafacts.summary
AS covid WHERE
county_fips_code = '24029' ORDER BY date DESC limit 1); -- set the multiplier set multiplier = 100;--Do the final math. select caseDiff / ConfirmedCases * multiplier as result;
MY QUESTION: Recognizing that I have a lot to learn and some definitely cleanup in this query, but result I get in Bigquery is correct, but I'm getting:
- View Result
- View Result
- View Result
- View Result
Where the final 'view result' is the answer I want. How can I get this code to just yield the answer (similar to simply running a select ((Answer)) from ((Table)).