2022. sze 14.

Compensation outliers SOLUTION

írta: dataanalyticsdemo
Compensation outliers SOLUTION

DataLemur, easy tier

Tovább Szólj hozzá

2022. ápr 26.

COVID monthly NEW cases HU

írta: dataanalyticsdemo
COVID monthly NEW cases HU

and monthly confirmed cases total

with data_21 as (
select * from (
select country_region, date as date_21, confirmed as confirmed_21, deaths as deaths_21
,LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) AS prev_day_21
,confirmed - LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) as new_cases_21
from `bigquery-public-data.covid19_jhu_csse.summary`
WHERE upper(country_region) = 'HUNGARY' AND date between '2020-01-01'
AND (select max(date) from `bigquery-public-data.covid19_jhu_csse.summary`)
)),

MONTHLY_NEW_CASES AS (
select
left(cast(date_21 as string),7) as yearmonth
,sum(new_cases_21) as res
from data_21
group by 1
order by 1 asc
),

TOTAL_CASES_MONTHS AS (
SELECT
left(cast(date_21 as string),7) as yearmonth
,MAX(confirmed_21) as res
from data_21
group by 1
order ...

Tovább Szólj hozzá

2022. feb 26.

PowerBI use value from another table

írta: dataanalyticsdemo
PowerBI use value from another table

Variables in DAX formulas

Let's make a summarized a table:

Profit_Table =
SUMMARIZECOLUMNS (
Orders[State] ,
Orders ,
"Profit by state" , sum ( Orders[Profit] )
)

 

Now, we have a separate excel file with 2 values

Let's make our summarized table use this profit value.

Profit_Acceptable =
var profitlimit = max ( VariableTable[ProfitPass] )
return
if ( Profit_Table[Profit by state] >= profitlimit , 1 , 0 )
I know what-if parameters can also be used, but in my experience
they tend to froze with big numbers.
Tovább Szólj hozzá

2022. feb 12.

COVID monthly cases HU

írta: dataanalyticsdemo
COVID monthly cases HU

How did it get his high?

with data_21 as (
select * from (
select country_region, date as date_21, confirmed as confirmed_21, deaths as deaths_21
,LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) AS prev_day_21
,confirmed - LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) as new_cases_21
from `bigquery-public-data.covid19_jhu_csse.summary`
WHERE upper(country_region) = 'HUNGARY' AND date between '2022-01-01'
AND (select max(date) from `bigquery-public-data.covid19_jhu_csse.summary`)
))
select
*
from data_21

 

 

Tovább Szólj hozzá

2022. feb 12.

PowerBI see query behind visual

írta: dataanalyticsdemo
PowerBI see query behind visual

Step 1: Turn on performance analyzer and select the analyze this visual option.

After that, performance analyzer adds some lines:

Click copy query and paste anywhere:

And you see, there is the distinct value on it. Let's add something unique, like the orderID:

These are auto-generated in the background..And we reached the end of this idea.

Tovább Szólj hozzá

2022. feb 03.

Exploring public complaint data

írta: dataanalyticsdemo
Exploring public complaint data

Special focus on the coyotes

Let's see the metadata first

SELECT column_name, data_type, description
FROM
`bigquery-public-data`

.austin_311.

INFORMATION_SCHEMA.COLUMN_FIELD_PATHS
WHERE
table_name="311_service_requests"

 Let's see how many years this database encompasses:

Looks like a lot of time.

As the dataset seems to have changed or disappeared from the public database, this is the end of this analysis.

coyote2.jpg

Tovább Szólj hozzá

2021. dec 30.

COVID CASES HU last 3 months

írta: dataanalyticsdemo
COVID CASES HU last 3 months

Same as always, the weekends get added to the next Monday's results.

This causes spikes, however we can see that these spikes are going down too fortunately.

Let's remove these spike days.

Doesn't really change. Looks like they test more on the beginning of the week and by the end, it drops.

with data_21 as (
select * from (
select country_region, date as date_21, confirmed as confirmed_21, deaths as deaths_21
,LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) AS prev_day_21
,confirmed - LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) as new_cases_21
from `bigquery-public-data.covid19_jhu_csse.summary`
WHERE upper(country_region) = 'HUNGARY' AND date between '2021-10-01'
AND (select max(date) from ...

Tovább Szólj hozzá

2021. dec 09.

Power BI Date Intelligence setup

írta: dataanalyticsdemo
Power BI Date Intelligence setup

Mistakes to avoid

For this to work, we need a Calendar table, or in another name a date table.

Why isn't one of our existing columns in our data good? Because:
-we need a table which contains all dates without skipping non-business days, holidays etc so all 365 days in a year.
-all the dates must occur only once (while in our tables multiple transactions can happen in a day or even none at all)

So let's create this table, the easiest was is through DAX calendarauto function. This will cover our dateframe which is existing in our dataset.

The main date column has to be set in DATE FORMAT. NOT DATETIME. Make sure you have in DATE format through any means necessary.

When this is done, you need to create the relationship between this, and your tables. This is done in a relatively easy way as ...

Tovább Szólj hozzá

2021. dec 07.

Power BI playing with dates

írta: dataanalyticsdemo
Power BI playing with dates

Data source: Superstore sample

Filter Sum of profit AFTER A SPECIFIC DATE with only GUI options:

Profit is set to whole number just for readability.

--------------------------------------------------

Filter with parameter and DAX formulas:

1. Add paramter

2. Convert parameter to query for referencing it in the formula:

3. Create DAX formula

4. Check if results are the same

Excel check returns the same,so it works.

----------------------------------------------------------------------

Use filters to select specific data:

 Some other touches:

Tovább Szólj hozzá

2021. nov 20.

COVID CASES HU 2020 vs 2021 comparison

írta: dataanalyticsdemo
COVID CASES HU 2020 vs 2021 comparison

From September 1 to Nov 19

What is going on?

Table:

country_region date_20 new_cases_20 date_21 confirmed_21 new_cases_21
Hungary 2020-09-02 365 2021-09-02 812793 262
Hungary 2020-09-03 301 2021-09-03 813040 247
Hungary 2020-09-06 495 2021-09-06 813688 648
Hungary 2020-09-07 576 2021-09-07 813818 130
Hungary 2020-09-08 341 2021-09-08 814064 246
Hungary 2020-09-09 411 2021-09-09 814409 345
Hungary 2020-09-10 476 2021-09-10 814732 323
Hungary 2020-09-13 484 2021-09-13 815605 873
Hungary 2020-09-14 844 2021-09-14 815851 246
Hungary 2020-09-15 726 ...

Tovább Szólj hozzá

2021. okt 21.

COVID NEW CASES HU daily 2021.09.21-2021.10.20

írta: dataanalyticsdemo
COVID NEW CASES HU daily 2021.09.21-2021.10.20

select *
from (
select country_region, date, confirmed, deaths
,LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) AS prev_day
,confirmed - LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) as new_cases
from `bigquery-public-data.covid19_jhu_csse.summary`
WHERE upper(country_region) = 'HUNGARY' AND
date between '2021-09-21' AND (select max(date) from
`bigquery-public-data.covid19_jhu_csse.summary`)
)
WHERE new_cases > 0
ORDER BY 2 asc

Tovább Szólj hozzá

2021. sze 22.

COVID NEW CASES HU daily 2021.08.01-2021.09.21

írta: dataanalyticsdemo
COVID NEW CASES HU daily 2021.08.01-2021.09.21

select *
from (
select country_region, date, confirmed, deaths, recovered, active
,LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) AS prev_day
,confirmed - LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) as new_cases
from `bigquery-public-data.covid19_jhu_csse.summary`
WHERE upper(country_region) = 'HUNGARY' AND
date between '2021-07-30' AND (select max(date) from
`bigquery-public-data.covid19_jhu_csse.summary`)
)
WHERE new_cases >0
ORDER BY 2 asc

Tovább Szólj hozzá

2021. sze 13.

COVID Cases Hungary

írta: dataanalyticsdemo
COVID Cases Hungary

select *
from (
select country_region, date, confirmed, deaths, recovered, active
,LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) AS prev_day
,confirmed - LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) as new_cases
from `bigquery-public-data.covid19_jhu_csse.summary`
WHERE upper(country_region) = 'HUNGARY' AND
date between '2021-07-30' AND (select max(date) from
`bigquery-public-data.covid19_jhu_csse.summary`)
)
WHERE new_cases >0
ORDER BY 2 asc

Tovább Szólj hozzá

2021. aug 23.

Israel Covid Cases (Google Public data, BigQuery)

írta: dataanalyticsdemo
Israel Covid Cases (Google Public data, BigQuery)

More testing maybe? From single digits to quadruple digits in 2 months :(

select country_region, date, confirmed, deaths, recovered, active
,LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) AS prev_day
,confirmed - LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) as new_cases
from `bigquery-public-data.covid19_jhu_csse.summary`
WHERE upper(country_region) = 'ISRAEL' AND
date between '2021-06-01' AND (select max(date) from
`bigquery-public-data.covid19_jhu_csse.summary`)

Tovább Szólj hozzá

COVID-19

2021. júl 10.

Bigquery Split Words with Regex

írta: dataanalyticsdemo
Bigquery Split Words with Regex

with prep as (
select 'John Doe' as name union all select 'Jane Doe' union all select 'ABC DEF'
)
select *
,Regexp_extract(name,r'^(?:[^\s]*\s){0}([^\s]*)\s?') as Word0
,Regexp_extract(name,r'^(?:[^\s]*\s){1}([^\s]*)\s?') as Word1
from prep

If there are more parts, there are no errors to those who have less:

 Great, I love it.

Tovább Szólj hozzá

2021. jún 04.

HU COVID cases II.

írta: dataanalyticsdemo
HU COVID cases II.

with check_countries as (
SELECT count(distinct country_region)
FROM `bigquery-public-data.covid19_jhu_csse.summary` LIMIT 1000
),
Hu_filter as (
select 'HU' as country, * from `bigquery-public-data.covid19_jhu_csse.summary`
where upper(country_region) = 'HUNGARY'
),
filtered as (
select date, confirmed, deaths, recovered, active
, LAG(confirmed, 1) OVER (PARTITION BY country ORDER BY date ASC) AS prev_day
from Hu_filter
WHERE date between '2021-03-01' and (select max(date) from `bigquery-public-data.covid19_jhu_csse.summary`)
)
select *,
confirmed - prev_day as new_cases
--,round(1-(deaths/confirmed),4) as survival_rate
from filtered
where confirmed - prev_day is not null
order by date asc

Tovább Szólj hozzá

2021. máj 28.

Leetcode 185: Department Top Three Salaries: My Solution

írta: dataanalyticsdemo
Leetcode 185: Department Top Three Salaries: My Solution

Free sample test question II.

with combined as (
select E.*, D.name as dep_name
from employee E
left join department D
on E.departmentid = d.id
),

ranked as (
select *
,dense_rank() over (partition by dep_name order by salary desc) as rn
from combined
)

select
dep_name as department,
name as Employee,
salary as Salary
from ranked where rn <= 3

Tovább Szólj hozzá

2021. máj 28.

Multiple tables in FROM

írta: dataanalyticsdemo
Multiple tables in FROM

Inspired by Leetcode "Consecutive numbers" question

Let's take this example table first:

Results in simple 8 lines:

When I use the same table 3 times in the FROM clause:

512 rows..But why? 8*8*8 = 512.

So you need to narrow that combination down with the commented part:

Now we have the same table, 3 times, without the weired combinations.

Tovább Szólj hozzá

2021. máj 03.

Get the value of the text in the form

írta: dataanalyticsdemo
Get the value of the text in the form

Demo for the other post

Get the value of the text in the form, TRY IT OUT:


Tovább Szólj hozzá

JavaScript TagManager

2021. máj 03.

India COVID spike in Bigquery

írta: dataanalyticsdemo
India COVID spike in Bigquery

with check_countries as (
SELECT count(distinct country_region)
FROM `bigquery-public-data.covid19_jhu_csse.summary` LIMIT 1000
),

India_filter as (
select
country_region,
date,
sum(confirmed) as confirmed,
sum(deaths) as deaths,
sum(recovered) as recovered,
sum(active) as active
FROM `bigquery-public-data.covid19_jhu_csse.summary`
where upper(country_region) = 'INDIA'
GROUP BY 1,2
),

filtered as (
select date, confirmed, deaths, recovered, active
, LAG(confirmed, 1) OVER (PARTITION BY country_region ORDER BY date ASC) AS prev_day
from India_filter
WHERE date between '2021-02-01' and (select max(date) from `bigquery-public-data.covid19_jhu_csse.summary`)
),

usual_tbl as (
select *,
confirmed - prev_day as new_cases
--,round(1-(deaths/confirmed),4) as survival_rate
from ...

Tovább Szólj hozzá

2021. ápr 19.

Transactions by browser in July 2017

írta: dataanalyticsdemo
Transactions by browser in July 2017

Analytics sample in BQ

SELECT
device.browser,
SUM ( totals.transactions ) AS total_transactions
FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*`
WHERE
_TABLE_SUFFIX BETWEEN '20170701' AND '20170731'
GROUP BY device.browser
HAVING SUM ( totals.transactions ) > 0
ORDER BY
total_transactions DESC

Tovább Szólj hozzá

public SQL Analytics Bigquery TABLE SUFFIX

2021. ápr 10.

HU Covid cases

írta: dataanalyticsdemo
HU Covid cases

with check_countries as (
SELECT count(distinct country_region)
FROM `bigquery-public-data.covid19_jhu_csse.summary` LIMIT 1000
),
Hu_filter as (
select 'HU' as country, * from `bigquery-public-data.covid19_jhu_csse.summary`
where upper(country_region) = 'HUNGARY'
),
filtered as (
select date, confirmed, deaths, recovered, active
, LAG(confirmed, 1) OVER (PARTITION BY country ORDER BY date ASC) AS prev_day
from Hu_filter
WHERE date between '2020-03-01' and (select max(date) from `bigquery-public-data.covid19_jhu_csse.summary`)
)
select *,
confirmed - prev_day as new_cases
--,round(1-(deaths/confirmed),4) as survival_rate
from filtered
order by date asc

Tovább Szólj hozzá

public SQL COVID-19 Bigquery

2021. ápr 08.

RO Covid cases

írta: dataanalyticsdemo
RO Covid cases

with check_countries as (
SELECT count(distinct country_region)
FROM `bigquery-public-data.covid19_jhu_csse.summary` LIMIT 1000
),
Ro_filter as (
select 'HU' as country, * from `bigquery-public-data.covid19_jhu_csse.summary`
where upper(country_region) = 'ROMANIA'
),
filtered as (
select date, confirmed, deaths, recovered, active
, LAG(confirmed, 1) OVER (PARTITION BY country ORDER BY date ASC) AS prev_day
from Hu_filter
WHERE date between '2021-01-01' and (select max(date) from `bigquery-public-data.covid19_jhu_csse.summary`)
)
select *,
confirmed - prev_day as new_cases
--,round(1-(deaths/confirmed),4) as survival_rate
from filtered
order by date asc

Tovább Szólj hozzá

public SQL COVID-19 Bigquery

2021. már 30.

Texas new COVID cases until 03.29

írta: dataanalyticsdemo
Texas new COVID cases until 03.29

 with prep as (
SELECT *
, LAG(confirmed_cases, 1)
OVER (PARTITION BY state_name ORDER BY date ASC) AS prev_day
FROM `bigquery-public-data.covid19_nyt.us_states`
where upper(state_name) = 'TEXAS'
and date >= '2021-03-01'
order by date asc
)

select date
, confirmed_cases - prev_day as new_cases --since the prev.day
from prep
order by date asc

Tovább Szólj hozzá

public SQL COVID-19 Bigquery

süti beállítások módosítása