Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Cannot Convert value '' of type Text to number

HI All,   I'm using the Dataset from below link   UNLOCODE DATASET   Essentially what I'm trying to do is convert the Coordinates to Latitude and Longitude. Got the basic formula from below lin...
  • Anonymous's avatar
    Anonymous
    7 years ago

    I went off and did some studying and put this together. Does it all in Power Query now

     

    let
        Source = Csv.Document(Web.Contents("https://datahub.io/core/un-locode/r/code-list.csv"),[Delimiter=",", Columns=12, Encoding=1252, QuoteStyle=QuoteStyle.None]),
        #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Change", type text}, {"Country", type text}, {"Location", type text}, {"Name", type text}, {"NameWoDiacritics", type text}, {"Subdivision", type text}, {"Status", type text}, {"Function", type text}, {"Date", Int64.Type}, {"IATA", type text}, {"Coordinates", type text}, {"Remarks", type text}}),
        #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Change", "Remarks", "IATA", "Date", "Function", "Status", "Subdivision", "Name"}),
        #"Add UNLOCODE" = Table.AddColumn(#"Removed Columns", "UN LOCODE", each [Country] & [Location]),
        #"Move UNLOCODE to Start" = Table.ReorderColumns(#"Add UNLOCODE",{"UN LOCODE", "Country", "Location", "NameWoDiacritics", "Coordinates"}),
        #"Remove Country and Location" = Table.RemoveColumns(#"Move UNLOCODE to Start",{"Country", "Location"}),
        #"Renamed Name col" = Table.RenameColumns(#"Remove Country and Location",{{"NameWoDiacritics", "Name"}}),
        #"Remove Blank Coordinates" = Table.SelectRows(#"Renamed Name col", each ([Coordinates] <> "")),
        #"Add LEN" = Table.AddColumn(#"Remove Blank Coordinates", "LEN", each Text.Length([Coordinates])),
        #"Add LAT split" = Table.AddColumn(#"Add LEN", "LAT split", each Text.Start([Coordinates],
    Text.PositionOf([Coordinates], " "))),
        #"Add LONG split" = Table.AddColumn(#"Add LAT split", "LONG split", each Text.Trim(
    Text.Middle([Coordinates],
    Text.PositionOf([Coordinates]," ")
    ,10)
    )),
        #"Add LDeg" = Table.AddColumn(#"Add LONG split", "LDeg", each Number.FromText(
    Text.Start([LAT split],2)
    )),
        #"Add LMin" = Table.AddColumn(#"Add LDeg", "LMin", each Number.FromText(
    Text.Range([LAT split],2,2)
    )),
        #"Add LSec ini" = Table.AddColumn(#"Add LMin", "LSec ini", each Text.Range([Coordinates],4,1)),
        #"Add LSec" = Table.AddColumn(#"Add LSec ini", "LSec", each if [LSec ini] = "N" or [LSec ini] = "S"
    then
    0
    else
    Number.FromText([LSec ini])),
        #"Add LDir" = Table.AddColumn(#"Add LSec", "LDir", each if
    [LSec ini] = "N"
    then
    1
    else
    -1),
        #"Added Custom" = Table.AddColumn(#"Add LDir", "LAT", each ([LDeg] +
    ([LMin]/60) +
    ([LSec]/3600)
    ) *
    [LDir]),
        #"Remove all LAT calc cols" = Table.RemoveColumns(#"Added Custom",{"LDeg", "LMin", "LSec ini", "LSec", "LDir", "LAT split"}),
        #"Add LoDeg" = Table.AddColumn(#"Remove all LAT calc cols", "LoDeg", each Number.FromText(
    Text.Start([LONG split],2)
    )),
        #"Add LoMin" = Table.AddColumn(#"Add LoDeg", "LoMin", each Number.FromText(
    Text.Range([LONG split],2,2)
    )),
        #"Add LoSec" = Table.AddColumn(#"Add LoMin", "LoSec", each if
    Text.Length([LONG split]) = 7
    then
    Number.FromText(
    Text.Range([LONG split],4,2)
    )
    else
    Number.FromText(
    Text.Range([LONG split],4,1)
    )),
        #"Add LoDir" = Table.AddColumn(#"Add LoSec", "LDir", each if
    Text.End([LONG split],1) = "W"
    then
    -1
    else
    1),
        #"Add LONG" = Table.AddColumn(#"Add LoDir", "LONG", each ([LoDeg] +
    ([LoMin]/60) +
    ([LoSec]/3600)) *
    [LDir]),
        #"Remove all other columns" = Table.RemoveColumns(#"Add LONG",{"LONG split", "LoDeg", "LoMin", "LoSec", "LDir", "Coordinates", "LEN"})
    in
        #"Remove all other columns"