title | author | date updated | keyword | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
tech layoff analysis |
Johnney Cao |
2023-04-24 |
|
This page provides a detailed guide on how to analyze tech layoffs data using Power BI. It includes information on data sources, parameters, and steps for retrieving and processing data from Kaggle. The document also includes sample Power Query scripts and a description of the reports that can be generated from the data.
- StarDate: Required, Type as
Date
- FileFolder: Required, Type as
Text
-
Date Table
-
Year Table
-
LastRefreshed Table
License: Open Database, Contents: © Original Authors.
Some data such as the sources, list of employees laid off and date of addition has been omitted here and the complete data can be found on Layoffs.fyi. Credits: Roger Lee
- Manual download the csv files from Source 1 (Kaggle) and Source 2 (Kaggle) to a local folder (same as FileFolder parameter), e.g
c:\Downloads
; - Retrieve the data from downloaded csv file;
- Promote first line as header;
- Clean up empty Company from list;
- Change percentage_laid_off to Percentage type and date or date_added to
Date
type; - Trim and clean all the text fields;
- Replace empty value in industry to
Other
; - Add a location column from city and country;
- Add a Stage Ranking column from stage;
- Subsidiary as 20,
- Merged as 30,
- Seed as 40,
- Series A-C as 50,
- Series D and above as 60,
- Post IPO as 90,
- else as 0
- Combine Company and date to a Primary Key;
=Text.Combine({[Company], "|", Date.ToText([Date], "yyyy"),Date.ToText([Date], "MM"), Date.ToText([Date], "dd")})
- Remove the duplicate record from table;
- Append two source tables into a new table, and unselect
enable load
for both source tables; - Remove duplicate records base on Key
- Changed source field to
Web URL
in Data Catagory
let
Source = Csv.Document(File.Contents(FileFolder&"\layoffs.csv"),[Delimiter=",", Columns=9, Encoding=65001, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each true),
#"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows",{{"company", type text}, {"location", type text}, {"industry", type text}, {"total_laid_off", Int64.Type}, {"percentage_laid_off", Percentage.Type}, {"date", type date}, {"stage", type text}, {"country", type text}, {"funds_raised", Int64.Type}}),
#"Replaced Other Industry" = Table.ReplaceValue(#"Changed Type","","Other",Replacer.ReplaceValue,{"industry"}),
#"Replaced Unknown stage" = Table.ReplaceValue(#"Replaced Other Industry","","Unknown",Replacer.ReplaceValue,{"stage"}),
#"Trimmed Text" = Table.TransformColumns(#"Replaced Unknown stage",{{"company", Text.Trim, type text}, {"location", Text.Trim, type text}, {"industry", Text.Trim, type text}, {"country", Text.Trim, type text}, {"stage", Text.Trim, type text}}),
#"Cleaned Text" = Table.TransformColumns(#"Trimmed Text",{{"company", Text.Clean, type text}, {"location", Text.Clean, type text}, {"industry", Text.Clean, type text}, {"country", Text.Clean, type text}, {"stage", Text.Clean, type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Cleaned Text",{{"location", "city"}}),
#"Inserted Merged Column" = Table.AddColumn(#"Renamed Columns", "location", each Text.Combine({[city], ", ", [country]}), type text),
#"Removed Duplicates" = Table.Distinct(#"Inserted Merged Column", {"company", "total_laid_off", "percentage_laid_off", "date", "location"}),
#"Added Stage Ranking" = Table.AddColumn(#"Removed Duplicates", "Stage Ranking", each if Text.Contains([stage], "IPO") then 90 else if Text.Contains([stage], "Private") then 80 else if Text.Contains([stage], "Subsidiary") then 20 else if Text.Contains([stage], "Acquired") then 30 else if Text.Contains([stage], "Merged") then 30 else if [stage] = "Seed" then 40 else if [stage] = "Series A" then 50 else if [stage] = "Series B" then 50 else if [stage] = "Series C" then 50 else if Text.StartsWith([stage], "Series") then 60 else 0),
#"Filtered Empty Lines" = Table.SelectRows(#"Added Stage Ranking", each ([company] <> null and [company] <> "" and [company] <> "#Paid" and [company] <> "&Open")),
#"Added Custom" = Table.AddColumn(#"Filtered Empty Lines", "Key", each Text.Combine({[company], "|", Date.ToText([date], "yyyy"),Date.ToText([date], "MM"), Date.ToText([date], "dd")}))
in
#"Added Custom"
let
Source = Csv.Document(File.Contents(FileFolder&"\layoffs_data.csv"),[Delimiter=",", Columns=11, Encoding=65001, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each true),
#"Remove Empty Lines" = Table.SelectRows(#"Filtered Rows", each ([Company] <> null and [Company] <> "" and [Company] <> "#Paid" and [Company] <> "&Open")),
#"Replaced Other Industry" = Table.ReplaceValue(#"Remove Empty Lines","","Other",Replacer.ReplaceValue,{"Industry"}),
#"Replaced Unknown stage" = Table.ReplaceValue(#"Replaced Other Industry","","Unknown",Replacer.ReplaceValue,{"Stage"}),
#"Trimmed Text" = Table.TransformColumns(#"Replaced Unknown stage",{{"Company", Text.Trim, type text}, {"Location_HQ", Text.Trim, type text}, {"Industry", Text.Trim, type text}, {"Country", Text.Trim, type text}, {"Stage", Text.Trim, type text}, {"Source", Text.Trim, type text}}),
#"Cleaned Text" = Table.TransformColumns(#"Trimmed Text",{{"Company", Text.Clean, type text}, {"Location_HQ", Text.Clean, type text}, {"Industry", Text.Clean, type text}, {"Country", Text.Clean, type text}, {"Stage", Text.Clean, type text}, {"Source", Text.Clean, type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Cleaned Text",{{"Location_HQ", "city"}}),
#"Inserted Merged Column" = Table.AddColumn(#"Renamed Columns", "Location", each Text.Combine({[city], ", ", [Country]}), type text),
#"Removed Duplicates" = Table.Distinct(#"Inserted Merged Column", {"Company", "Laid_Off_Count", "Percentage", "Date", "Location"}),
#"Added Stage Ranking" = Table.AddColumn(#"Removed Duplicates", "Stage Ranking", each if Text.Contains([Stage], "IPO") then 90 else if Text.Contains([Stage], "Private") then 80 else if Text.Contains([Stage], "Subsidiary") then 20 else if Text.Contains([Stage], "Acquired") then 30 else if Text.Contains([Stage], "Merged") then 30 else if [Stage] = "Seed" then 40 else if [Stage] = "Series A" then 50 else if [Stage] = "Series B" then 50 else if [Stage] = "Series C" then 50 else if Text.StartsWith([Stage], "Series") then 60 else 0),
#"Changed Type" = Table.TransformColumnTypes(#"Added Stage Ranking",{{"Company", type text}, {"city", type text}, {"Industry", type text}, {"Laid_Off_Count", Int64.Type}, {"Date", type datetime}, {"Source", type text}, {"Funds_Raised", Int64.Type}, {"Stage", type text}, {"Date_Added", type datetime}, {"Country", type text}, {"Percentage", Percentage.Type}, {"Location", type text}, {"Stage Ranking", Int64.Type}}),
#"Changed Date" = Table.TransformColumnTypes(#"Changed Type",{{"Date", type date}, {"Date_Added", type date}}),
#"Added Index Key" = Table.AddColumn(#"Changed Date", "Key", each Text.Combine({[Company], "|", Date.ToText([Date], "yyyy"),Date.ToText([Date], "MM"), Date.ToText([Date], "dd")})),
#"Renamed Columns1" = Table.RenameColumns(#"Added Index Key",{{"Company", "company"}, {"Industry", "industry"}, {"Laid_Off_Count", "total_laid_off"}, {"Date", "date"}, {"Source", "source"}, {"Funds_Raised", "funds_raised"}, {"Stage", "stage"}, {"Date_Added", "date_added"}, {"Country", "country"}, {"Percentage", "percentage_laid_off"}, {"Location", "location"}})
in
#"Renamed Columns1"
let
Source = Table.Combine({layoffs_source2, layoffs_source1}),
#"Reordered Columns" = Table.ReorderColumns(Source,{"Key", "company", "city", "industry", "total_laid_off", "date", "source", "funds_raised", "stage", "date_added", "country", "percentage_laid_off", "location", "Stage Ranking"}),
#"Removed Duplicates" = Table.Distinct(#"Reordered Columns", {"Key"}),
#"Replaced Value" = Table.ReplaceValue(#"Removed Duplicates",null,0,Replacer.ReplaceValue,{"percentage_laid_off"})
in
#"Replaced Value"
Tables | Relationship |
---|---|
Layoffs / DateTable | Many to 1 |
- Map - Geo Graphic view by layoff number per city / country
- Ribbon chart - Count of company by Country
- Ribbon chart - number of Layoffs by Country
- Line and Stacked Column Chart - Count of company and number of Layoffs by Company Stage and country
- Scatter Chart - Count of company and number of layoffs by Industry
- Stacked Bar Chart - number of Layoffs by company and country
- Scatter Chart - Count of company and number of layoffs by Industry