How to display 0 for missing records while blending data Google Data Studio? - business-intelligence

I am attempting to blend two data sources in Google Data Studio:
Data Source 1. weekly sales numbers by market (example below)
ID
WeekEndingDate
Market
Sales
1
7/17/2022
Utah
$400
2
7/17/2022
Arizona
$500
3
7/17/2022
Colorado
$600
4
7/17/2022
Dallas Fort Worth
$700
5
7/10/2022
Utah
$400
6
7/10/2022
Colorado
$300
7
7/10/2022
Dallas Fort Worth
$800
8
7/10/2022
Arizona
$600
9
7/10/2022
Utah
$500
10
7/10/2022
Colorado
$100
Data Source 2. weekly budget by market (Example below)
WeekEndingDate
Market
Sales Budget
7/17/2022
Utah
$5000
7/17/2022
Arizona
$4000
7/17/2022
Colorado
$3000
7/17/2022
Dallas Fort Worth
$2000
7/17/2022
Tennessee
$1000
7/17/2022
Oregon
$1000
7/10/2022
Utah
$5000
7/10/2022
Arizona
$4000
7/10/2022
Colorado
$300
7/10/2022
Dallas Fort Worth
$2000
7/10/2022
Tennessee
$1000
7/10/2022
Oregon
$1000
What I Want in Data Studio Table (Example below) I have bolded the rows that I am unable to get in my table. The rest of the rows I am able to get perfectly.
WeekEndingDate
Market
Sales Budget
Sales
7/17/2022
Utah
$5000
$400
7/17/2022
Arizona
$4000
$500
7/17/2022
Colorado
$3000
$600
7/17/2022
Dallas Fort Worth
$2000
$700
7/17/2022
Tennessee
$1000
$0
7/17/2022
Oregon
$1000
$0
7/10/2022
Utah
$5000
$900
7/10/2022
Arizona
$4000
$600
7/10/2022
Colorado
$3000
$400
7/10/2022
Dallas Fort Worth
$2000
$800
7/10/2022
Tennessee
$1000
$0
7/10/2022
Oregon
$1000
$0
My blend in data studio
What I am able to generate in Data Studio Please see this data as a reference for the screenshot below https://docs.google.com/spreadsheets/d/1nZbuX7x--BoO63sDmv4b3NaeL3ixaInl4IWsyXfnLLo/edit#gid=1617242817
I have successfully created an inner join blend between the two data sources linking the week date and the market. The data is pulling almost perfectly and I am like 98% done, however, what I am having trouble with is that data source #2 has weekly budget records for weeks that do not exist in data source #1 and those weeks will not show up on my table in data studio (ex. week ending 7/17/2022 for Tennessee budget is $2,000 but no sales were made in week ending 7/17/2022 in Tennessee, therefore, there are no records of sales for week ending 7/17/2022 in data source 1).
I currently have in a simple table each weeks sales and budget in two different columns but week 7/17/2022 is missing because there are no records for week ending 7/17/2022 in data source 1 to match the week in source 2. I need to display that week 7/17/2022's budget for tennessee is $2,000 and that there were $0 in sales for that week. Does anyone have an ideas on how I can accomplish this?
PS - I attempted a full outer join of the two data sources and there was no difference.
UPDATE - sorry for the lack of information at first. I have compiled some data that will hopefully help clarify this issue and you can find the data here: https://docs.google.com/spreadsheets/d/1nZbuX7x--BoO63sDmv4b3NaeL3ixaInl4IWsyXfnLLo/edit?usp=sharing
You can also find a sample data studio report that you can view how I have it currently setup based on the sample data in the google sheet link above: https://datastudio.google.com/reporting/adfc3ee5-6a9f-4c57-b66f-cff27e91850e
I have also added some sample tables directly on Stackoverflow for a quicker sample view.

0) Summary
Looks at the issue
Solution #1 - Left outer join
1) Background and Issue
To visualise the issue and let's focus on the values where WeekEndingDate is Jul 17, 2022 and look at the values in the Market field:
WeekEndingDate
Market
Data Source 1
Data Source 2
Jul 17, 2022
Utah
✅
✅
Jul 17, 2022
Arizona
✅
✅
Jul 17, 2022
Dallas Fort Worth
✅
✅
Jul 17, 2022
Colorado
✅
✅
Jul 17, 2022
Oregon
✅
✅
Jul 17, 2022
Nevada
❌
✅
Jul 17, 2022
Tennessee
❌
✅
As indicated by the ❌, two Market values (Nevada and Tennessee) are available in Data Source 2 but not in Data Source 1
2) Suggestion #1: Left Outer Join
Shift the data sources so that data source 2 is on the left and data source 1 is on the right and then left outer join:
2.1) Blend Fields
Description
Table 1
Table 2
Data Source:
2
1
Dimension 1:
WeekEndingDate
WeekEndingDate
Dimension 2:
Market
Market
Metric 1:
Sales Budget
Sales
Date Range:
WeekEndingDate (Auto)
WeekEndingDate (Auto)
Image:
2.2) Join Configuration
Description
Table 1 🔗 Table 2
Join Operator:
Left Outer
Join Condition 1:
WeekEndingDate (Data Source 2) 🔗 WeekEndingDate (Data Source 1)
Join Condition 2:
Market (Data Source 2) 🔗 Market (Data Source 1)
Image:
Publicly editable Google Data Studio report (embedded Google Sheets data source) to elaborate:

Related

AWS Quicksight - How do I group by sum and then average?

I've just started using Quicksight and I can't for the life of me figure this out.
Let's say I have a table that goes like this :
date
country
color
nb_sales
10-11
USA
Black
10
10-11
USA
Blue
5
10-12
USA
Blue
20
10-11
UK
Black
10
10-12
UK
Black
15
10-11
UK
Blue
15
What I want is the average daily number of sales by country, preferably in a pieplot :
country
avg_nb_sales
USA
17.5
UK
20
So I need first to group by date, country and sum the ratings and then once this aggregation is done I need the average by country. I thought I should be using avgOver(sum(ratings), country) but I can't get it right.
So how do I achieve that ?
I thank you for your time.
I have managed to get the result expected though not sure that it is the best way to do it (especially if you have some dates when you get sales only for one country):
avgOver(sum(sales), [country])/distinct_count(date)

Sort a file using numeric column start and end delimiters

I have a file, and I wish to sort by the second column, the problem is that the data columns contain spaces. How to sort alphabetically by the second column, then by the third (Numeric) column?
I tried sort -k44,62 and do not get the expected answer. i.e. Alphabetical sort based on column 2.
Starbucks Seattle 291,000
Costco Wholesale Issaquah 245,000
Microsoft Redmond 134,944
Barrett Business Services Vancouver 115,746
Nordstrom Seattle 74,000
T-Mobile Bellevue 51,000
The Hotel Group Edmonds 35,330
University of Washington Seattle 26,110
Fortive Everett 26,000
Paccar Bellevue 25,000
Providence Health & Services Renton 20,640
Expedia Group Bellevue 20,075
Savers Bellevue 20,000
Alaska Air Group Seattle 19,214
Expeditors Seattle 17,400
MultiCare Health System Tacoma 17,000
Esterline Technologies Bellevue 12,000
Recreational Equipment Kent 12,000
Carrix Seattle 11,000
Labor Ready Tacoma 10,000
SSA Marine Seattle 10,000
Nash Holdings Seattle 10,000
Trident Seafoods Seattle 9,000
Eddie Bauer Bellevue 8,000
Chief Seattle BSA Seattle 7,785
Laird Norton Co Seattle 7,500
Windermere Real Estate Seattle 7,000
Slalom Seattle 7,000
PeaceHealth Vancouver 6,690
Itron Liberty Lake 6,200
TrueBlue Tacoma 6,000
Nintendo Redmond 5,944
JACK FROST FRUIT Yakima 3,000
YAKIMA REGIONAL MED CARDIAC CENT Yakima 3,000
NORTH PUGET SOUND CENTER FOR SLEEP DISORDERS Everett 2,500
Chose a field delimiter that does not occur in the data and work on field 1:
sort -t '|' -k1.47,1.62 < f
To also sort numerically on the 3rd logical field:
sort -t '|' -k1.47,1.62 -k1.63n < f
Unfortunately the sort will break if all values are not in the range from 1,000 through 999,999.

PowerQuery order of words in Text.Combine

Using PowerQuery in Excel 2016 to combine words in one column by the Category stored in another column. I use GroupBy with Text.Combine in it.
I am expecting the order of words to be sustained but it seems random.
There are 3 pictures below
first is my original table before SORT.
MAPPED WORDS is what i need combined, CATEGORY is the bucket of the combinations,
POSITION is the column which indicates the position of MAPPED WORD in SKU - i sort words in that order expecting that Text.Combine would retain that in the final strings. I am interested in red and blue-highlighted words for this example.
ORIGINAL TABLE
Market Tag SKU Position Category Mapped Word
ABG 130 HELLO DAY CRYSTAL MIDI GRANOLA CHOCOLATE 11 BRAND Crystal
ABG 130 HELLO DAY CRYSTAL MIDI GRANOLA CHOCOLATE 7 BRAND Day
AAI 30 FINAX HEALTHY GOOD MUESLI APPLE NUT RAISIN 1 BRAND Finax
AAI 30 FINAX HEALTHY GOOD MUESLI APPLE NUT RAISIN 7 OTHER Healthy
ABG 130 HELLO DAY CRYSTAL MIDI GRANOLA CHOCOLATE 1 BRAND Hello
ABG 130 HELLO DAY CRYSTAL MIDI GRANOLA CHOCOLATE 19 BRAND Midi
AAI 30 FINAX HEALTHY GOOD MUESLI APPLE NUT RAISIN 20 TYPE Muesli
AAI 30 FINAX HEALTHY GOOD MUESLI APPLE NUT RAISIN 33 FLAVOURS Nuts
AAI 30 FINAX HEALTHY GOOD MUESLI APPLE NUT RAISIN 37 FLAVOURS Raisins
ABG 130 HELLO DAY CRYSTAL MIDI GRANOLA CHOCOLATE 32 FLAVOURS Chocolate
AAI 30 FINAX HEALTHY GOOD MUESLI APPLE NUT RAISIN 27 FLAVOURS Apple
ABG 130 HELLO DAY CRYSTAL MIDI GRANOLA CHOCOLATE 24 TYPE Granola
AAI 30 FINAX HEALTHY GOOD MUESLI APPLE NUT RAISIN 15 BRAND Good
AFTER SORT
AFTER GROUPBY-COMBINE.
The problem is that the result does not look like any logic - the order is ignored. Red words are appended in alphabetical order, whilst blue with no specific order.
I need the words combined in the order as per POSITION column.
It's the same answer I gave to a different question around operations after sorting, but I tested it and if you put your sorting step inside Table.Buffer() it seems like that works here as well.
Table.Buffer(Table.Sort(PROPERCASE_WORDS,{{"TAG",Order.Ascending},{"CATEGORY",Order.Ascending}, {"POSITION",Order.Ascending}}))
AFAIK Table.Buffer loads the table into memory and in doing so resets an internal index used by various PQ operations to match the current sorting of the table. I don't know if there are any downsides to doing this, but it seems to work in a number of cases where you want an operation to proceed in a "top to bottom" manner.

Region (not country) codes for table rates shipping in Magento 1.9

I'm adding table rates shipping method to a Magento install.
My rates are divided per weight in 6 different ranges 0-3 | 3-6 | 7-10 | 11-25 | 26-50 | 50-100 always the same in the whole Italy except for 3 regions.
In these regions prices for same weight ranges are slightly different. So It would be super good being able to add region codes into the right field, but where I can find those codes?
Headers into CSV are:
Country,Region/State,"Zip code","Weight (and Above)","Shipping Price"
I need to undrstand what I must add to the "Region/State" filed.
Adding different prices using Zip Codes would mean adding 7056 lines to my CV manually!
TNKS.
Go and look at this table in your magento database;
select * from directory_country_region
This reveal all the regions currently in your store;
1 US AL Alabama
2 US AK Alaska
3 US AS American Samoa
4 US AZ Arizona
5 US AR Arkansas
6 US AE Armed Forces Africa
7 US AA Armed Forces Americas
8 US AE Armed Forces Canada
9 US AE Armed Forces Europe
10 US AE Armed Forces Middle East
etc. Column C is the region code. You can add to this if required.

Algorithm/Model for assigning rounds of passengers in shared cars with scattered timetables

I am trying to model the following problem: a set of people (teacher of school in the reality) must reach the office each one at different hours (i.e. people 1 enters at hour 2 and exits at hour 7, people 2 enters at hour 4 exits at hour 6 and so on). These times changes depending on the day of the week following a given timetable.
In order to reach the office people with same starting hour meet in a common place and share a car. Similarly when they have to come back from office they will sort in the cars of drivers leaving at given hour to reach the common place near their houses. The problem is how to assign a driver and a crew for each turn so that:
all people can find place in a turn (both in departure and return)
in each turn there is a maximum number of persons (due to the limited car places)
minimize the total number of cars used
each person should drive the car the same number of the other (or make as even as possible the use of each car/driver)
The input therefore is a table like:
Mon: Andrew 1-3 (hour of departure-return), Bill 2-5, Cindy 1-7 ...
Tue: Andrew 2-7, Bill 1-6, Cindy 2-4 ...
Wed: ...
while the output should be
Mon: Departures: hour 1 (driver Andrew, crew: Cindy, Steve), hour 2 (driver Bill, crew: Steve, Frank)... Returns: hour 3 (driver Andrew, crew: Jim, Lisa), hour 4 (driver Mary, crew: David, Pete)...
Tue: Departures hour 1 (driver Bill, crew: Richard, Dan, Pete), hour 2 (driver Andrew, crew: Cindy, Bob) ...
Wed...

Resources