Forum Discussion
Changing data from imported websites
Changing units on site is done by java script, it doesn't affect returned table.
It's much better to do all transformations within the query - more reliable and to avoid risk of not syncing added data with returned by query.
I did that for Berlin, you may check steps in attached file. Script is
let
Source = Web.Page(Web.Contents("https://weather.com/weather/tenday/l/Berlin+Germany?canonicalCityId=49875d033efa3f8a515cc07b7ab1897df30ce65616175ffb4591cb95c5f646ff")),
Data0 = Source{0}[Data],
ColumnNames=List.FirstN(Table.ColumnNames(Data0),6),
RemoveDayColumn = Table.RemoveColumns(Data0,{"Day"}),
TempColumnNames = Table.ColumnNames(RemoveDayColumn),
ListOfList = List.Zip({TempColumnNames,ColumnNames}),
RenameTableColumns = Table.RenameColumns(RemoveDayColumn, ListOfList),
SplitWind = Table.SplitColumn(
RenameTableColumns,
"Wind",
Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv),
{"Wind.1", "Wind.2", "Wind.3"}
),
VelocityToNumber = Table.TransformColumnTypes(
SplitWind,
{
{"Wind.1", type text},
{"Wind.2", Int64.Type},
{"Wind.3", type text}
}
),
MphToKmh = Table.AddColumn(
VelocityToNumber,
"Custom",
each Number.ToText([Wind.2]*1.60934,"F1")
),
ReplaceUnit = Table.ReplaceValue(
MphToKmh,
"mph","km/h",
Replacer.ReplaceText,{"Wind.3"}
),
AddNewWind = Table.AddColumn(
ReplaceUnit,
"Wind",
each Text.Combine(
{[Wind.1], [Custom], [Wind.3]}, " "
),
type text
),
ReplaceNoTempreture = Table.ReplaceValue(
AddNewWind,
"--","--°",
Replacer.ReplaceText,
{"High / Low"}
),
SplitByDegreeCharacter = Table.SplitColumn(
ReplaceNoTempreture,
"High / Low",
Splitter.SplitTextByDelimiter("°", QuoteStyle.Csv),
{"High/Low.1", "High/Low.2", "High/Low.3"}
),
DegreeToNumber = Table.TransformColumnTypes(
SplitByDegreeCharacter,
{
{"High/Low.1", Int64.Type},
{"High/Low.2", Int64.Type},
{"High/Low.3", type text}
}
),
HighDfToDc = Table.ReplaceValue(
DegreeToNumber,
each [#"High/Low.1"],
each Number.ToText(([#"High/Low.1"] - 32)*5/9,"F1"),
Replacer.ReplaceValue,{"High/Low.1"}
),
LowDfToDc = Table.ReplaceValue(
HighDfToDc,
each [#"High/Low.2"],
each Number.ToText(([#"High/Low.2"] - 32)*5/9,"F1"),
Replacer.ReplaceValue,{"High/Low.2"}
),
ReplacErrors = Table.ReplaceErrorValues(
LowDfToDc,
{
{"High/Low.1", "--"},
{"High/Low.2", "--"}
}
),
InsertNewHighLow = Table.AddColumn(
ReplacErrors,
"High / Low",
each Text.Combine({[#"High/Low.1"], [#"High/Low.2"]}, "°") & "°",
type text
),
DayInOneString = Table.ReplaceValue(
InsertNewHighLow,
"#(cr)#(lf)",
" ",
Replacer.ReplaceText,{"Day"}
),
RemoveUnused = Table.SelectColumns(
DayInOneString,
{"Day", "Description", "High / Low", "Wind", "Precip", "Humidity"}
)
in
RemoveUnused
SergeiBaklan thank you for this, I appreciate it! However, when I paste the code (regardless which one) into the advanced editor in the power query editor, it says there is a "Token eof error", see image attached. The problem in both cases appears to be "let" at the beginning of both java scripts.
How do I circumvent this so that it runs because it doesn't let me close it without removing the token eof error?
Thanks again for helping
- SergeiBaklanDec 25, 2019Diamond Contributor
You shall not paste but replace the code. It shall be no two sequential let ... in blocks in one query, only one. In this sample we have EOF error since first in ends the script
let One = "a" in One let Two="b" in TwoHowever, blocks could be nested, like
let One = "a", Two = let Two="b" in Two in One & Twobut that's not your case here.
By the way, script which works in Power Query is called M-script. Java script works on web site, weather.com.
- Juri_MessenboeckDec 25, 2019Copper Contributor
Thank you for your help!
- SergeiBaklanDec 25, 2019Diamond Contributor
Juri_Messenboeck , you are welcome