Forum Discussion
Weather data
- 2 years ago
My query is just a sample as I don't have all your lat and long combinations. Create a custom column and paste that formula in the custom column step from the code I gave you which is a modified version of your code. Reference these two to the actual column names:
Latitude = [Lat Column], Longitude = [Lon Column],
Hi obertimanuel ,
What makes 150K lat and long combinations not possible? I'm thinking it is either due to API limitation or you are trying to extract too big of a data that your device is running out of memory. That aside, you can modify your query so you don't need to use an external custom function and avoid the dynamic data source warning. Here's a sample query:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JcnBDQAgCASwXXgTc3ogMItx/zU02m/XEq9WIIdTVDpaRIeBsvVd1uT0/Je0KN7bBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Lat Column" = _t, #"Lon Column" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Lat Column", type number}, {"Lon Column", type number}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Weather Data", each let
// Definisci i parametri di latitudine e longitudine
Latitude = [Lat Column],
Longitude = [Lon Column],
RelPath = "/locationforecast/2.0/compact?lat=" & Text.From(Latitude) & "&lon=" & Text.From(Longitude),
// Recupera i dati dall'API
Source = Web.Contents("https://api.met.no/weatherapi/", [RelativePath = RelPath]),
Json = Json.Document(Source),
// Naviga fino ai dati necessari
timeseries = Json[properties][timeseries],
// Trasforma i dati in una tabella
#"Converted to Table" = Table.FromList(timeseries, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"time", "data"}, {"time", "data"}),
#"Expanded data" = Table.ExpandRecordColumn(#"Expanded Column1", "data", {"instant", "next_1_hours"}, {"instant", "next_1_hours"}),
#"Expanded instant" = Table.ExpandRecordColumn(#"Expanded data", "instant", {"details"}, {"details"}),
#"Expanded details" = Table.ExpandRecordColumn(#"Expanded instant", "details", {"air_temperature", "wind_speed"}, {"air_temperature", "wind_speed"}),
// Gestisci i dati di precipitazione
#"Added Custom" = Table.AddColumn(#"Expanded details", "precipitation", each try Record.FieldOrDefault([next_1_hours][details], "precipitation_amount") otherwise 0),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"next_1_hours"}),
// Rinomina le colonne
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{
{"time", "Time"},
{"air_temperature", "Temperature"},
{"wind_speed", "WindSpeed"},
{"precipitation", "Precipitation"}
})
in
#"Renamed Columns"
, type table)
in
#"Added Custom"
You can see in the sreenshot above that by utilizing the parameters in Web.Contents, you are able to avoid the dynamic data source warning.
Remove the timezone from the data before converting it to date or datetime as not doing so will shift the time/date back by 2 hours (Norway is + 2 right) if the model is refreshed in the service.The service uses UTC.
Thanks,
How, after modifying the query, could I select a city front data filter , and automatically have the corresponding weather data with corresponding lat and lon?
- danextian2 years agoSuper User
If the data for that city is loaded into the model then you can.
- obertimanuel2 years agoFrequent Visitor
Thanks,
Can you explain how please ?I have only 2 lat e 2 lon........
I'm doing something wrong and I don't understand whereThanks
- danextian2 years agoSuper User
My query is just a sample as I don't have all your lat and long combinations. Create a custom column and paste that formula in the custom column step from the code I gave you which is a modified version of your code. Reference these two to the actual column names:
Latitude = [Lat Column], Longitude = [Lon Column],