Hi All
I'm a PQ newbie and have been learning to do my tasks with the help of the internet. Thank you for countless times you all have helped.
For this particular project, I've basically solved the problems using the answers I found on the internet. The issue is that it's taking too long to update. Here's what I'm trying to do.
Is there a way to upload the file? I don't see the option on here.
Here's the mcode:
Thanks and stay safe...
I'm a PQ newbie and have been learning to do my tasks with the help of the internet. Thank you for countless times you all have helped.
For this particular project, I've basically solved the problems using the answers I found on the internet. The issue is that it's taking too long to update. Here's what I'm trying to do.
- Grab data from the European CDC that has the daily update of COVID-19 cases and deaths by country
- Put it in a table and use PQ to transform the data to get the following:
- Calculate the running total of the daily cases so I can view the cumulative cases
- Calculate the first day of case in each country so I can time-align the curves
Is there a way to upload the file? I don't see the option on here.
Here's the mcode:
Code:
let
Source = Excel.CurrentWorkbook(){[Name="COVID19Data"]}[Content],
ChangeType = Table.TransformColumnTypes(Source,{{"DateRep", type date}, {"Day", Int64.Type}, {"Month", Int64.Type}, {"Year", Int64.Type}, {"Cases", Int64.Type}, {"Deaths", Int64.Type}, {"Countries and territories", type text}, {"GeoId", type text}}),
RemoveExtraColumns = Table.RemoveColumns(ChangeType,{"Day", "Month", "Year"}),
RenameCountryColumn = Table.RenameColumns(RemoveExtraColumns,{{"Countries and territories", "Geography"}}),
SortRows = Table.Sort(RenameCountryColumn,{{"Geography", Order.Ascending}, {"DateRep", Order.Ascending}}),
AddIndex = Table.AddIndexColumn(SortRows, "Row", 1, 1),
AddRunningTotal = Table.AddColumn(AddIndex, "Running Total", each let Group=[Geography], Row=[Row] in List.Sum(Table.SelectRows(AddIndex, each [Row]<=Row and [Geography]=Group)[Cases])),
RemoveZero = Table.SelectRows(AddRunningTotal, each ([Running Total] <> 0)),
GroupGeographies = Table.Group(RemoveZero, {"Geography"}, {{"GeoGroup", each _, type table [DateRep=date, Cases=number, Deaths=number, Geography=text, GeoId=text, Row=number, Running Total=number]}}),
AddGeoIndex = Table.AddColumn(GroupGeographies, "GeoIndex", each Table.AddIndexColumn([GeoGroup],"Day Number",1,1)),
RemovedGeoGroup = Table.RemoveColumns(AddGeoIndex,{"GeoGroup"}),
#"Expanded GeoIndex" = Table.ExpandTableColumn(RemovedGeoGroup, "GeoIndex", {"DateRep", "Cases", "Deaths", "Running Total", "Day Number"}, {"DateRep", "Cases", "Deaths", "Running Total", "Day Number"})
in
#"Expanded GeoIndex"
Thanks and stay safe...