首页 > 解决方案 > M 查询结果为“需要令牌文字”

问题描述

我在 Power Query 中收到“Expression.SyntaxError: Token Literal Expected”错误。我知道它告诉我它希望 [OffenseTeam] 是一个字符串文字,但这令人困惑,因为它是对包含该字符串的字段的引用?

let
Source = Csv.Document(File.Contents("C:\Users\xxxxx\Dropbox\My PC (xxxxxx)\Desktop\pbp-2020.csv"),[Delimiter=",", Columns=45, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"GameId", Int64.Type}, {"GameDate", type date}, {"Quarter", Int64.Type}, {"Minute", Int64.Type}, {"Second", Int64.Type}, {"OffenseTeam", type text}, {"DefenseTeam", type text}, {"Down", Int64.Type}, {"ToGo", Int64.Type}, {"YardLine", Int64.Type}, {"", type text}, {"SeriesFirstDown", Int64.Type}, {"_1", type text}, {"NextScore", Int64.Type}, {"Description", type text}, {"TeamWin", Int64.Type}, {"_2", type text}, {"_3", type text}, {"SeasonYear", Int64.Type}, {"Yards", Int64.Type}, {"Formation", type text}, {"PlayType", type text}, {"IsRush", Int64.Type}, {"IsPass", Int64.Type}, {"IsIncomplete", Int64.Type}, {"IsTouchdown", Int64.Type}, {"PassType", type text}, {"IsSack", Int64.Type}, {"IsChallenge", Int64.Type}, {"IsChallengeReversed", Int64.Type}, {"Challenger", type text}, {"IsMeasurement", Int64.Type}, {"IsInterception", Int64.Type}, {"IsFumble", Int64.Type}, {"IsPenalty", Int64.Type}, {"IsTwoPointConversion", Int64.Type}, {"IsTwoPointConversionSuccessful", Int64.Type}, {"RushDirection", type text}, {"YardLineFixed", Int64.Type}, {"YardLineDirection", type text}, {"IsPenaltyAccepted", Int64.Type}, {"PenaltyTeam", type text}, {"IsNoPlay", Int64.Type}, {"PenaltyType", type text}, {"PenaltyYards", Int64.Type}}),
//Sorted the records by game day, by game quarter, by game minute, by game second
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"GameId", Order.Ascending}, {"Quarter", Order.Ascending}, {"Minute", Order.Ascending}, {"Second", Order.Ascending}}),
#"Replaced Bad Q1 End" = Table.ReplaceValue(#"Sorted Rows","END QUARTER 1","BEGIN QUARTER 1",Replacer.ReplaceText,{"Description"}),
#"Replaced Bad Q2 End" = Table.ReplaceValue(#"Replaced Bad Q1 End","END QUARTER 2","BEGIN QUARTER 2",Replacer.ReplaceText,{"Description"}),
#"Replaced Bad Q3 End" = Table.ReplaceValue(#"Replaced Bad Q2 End","END QUARTER 3","BEGIN QUARTER 3",Replacer.ReplaceText,{"Description"}),
#"Replaced Bad Q4 End" = Table.ReplaceValue(#"Replaced Bad Q3 End","END QUARTER 4","BEGIN QUARTER 4",Replacer.ReplaceText,{"Description"}),
//Filtered out the "GAME" and "END GAME" events because they don't provide any information.  There are other records that can be keyed on (e.g. 1st QTR, Minute 0, Down 1 is first play of game). 
#"Filter Out Game / End of Game" = Table.SelectRows(#"Replaced Bad Q4 End", each ([Description] <> "END GAME" and [Description] <> "GAME")),
#"Create GameEventId" = Table.AddColumn(#"Filter Out Game / End of Game", "GameEventId", each Number.ToText([GameId])&if [OffenseTeam] = null and Text.Start([Description],7) = "Timeout" then "TO" else [OffenseTeam]&"_"&Number.ToText([Quarter])&"."&Number.ToText([Minute])&"."&Number.ToText([Second])),
//#"Create GameEventId" = Table.AddColumn(#"Filter Out Game / End of Game", "GameEventId", each Number.ToText([GameId])&[OffenseTeam] &"_"&Number.ToText([Quarter])&"."&Number.ToText([Minute])&"."&Number.ToText([Second])),
#"Reordered Columns" = Table.ReorderColumns(#"Create GameEventId",{"GameEventId", "GameId", "GameDate", "Quarter", "Minute", "Second", "OffenseTeam", "DefenseTeam", "Down", "ToGo", "YardLine", "", "SeriesFirstDown", "_1", "NextScore", "Description", "TeamWin", "_2", "_3", "SeasonYear", "Yards", "Formation", "PlayType", "IsRush", "IsPass", "IsIncomplete", "IsTouchdown", "PassType", "IsSack", "IsChallenge", "IsChallengeReversed", "Challenger", "IsMeasurement", "IsInterception", "IsFumble", "IsPenalty", "IsTwoPointConversion", "IsTwoPointConversionSuccessful", "RushDirection", "YardLineFixed", "YardLineDirection", "IsPenaltyAccepted", "PenaltyTeam", "IsNoPlay", "PenaltyType", "PenaltyYards"}),
#"Replaced LA with LAR - Off" = Table.ReplaceValue(#"Reordered Columns","LA","LAR",Replacer.ReplaceValue,{"OffenseTeam"}),
#"Replaced LA with LAR - Def" = Table.ReplaceValue(#"Replaced LA with LAR - Off","LA","LAR",Replacer.ReplaceValue,{"DefenseTeam"}),
//Got rid of records for beginning of quarters and 2-minute warnings
#"Filter Out Procedural Records" = Table.SelectRows(#"Replaced LA with LAR - Def", each [Description] <> "BEGIN QUARTER 1" and [Description] <> "BEGIN QUARTER 2" and [Description] <> "BEGIN QUARTER 3" and [Description] <> "BEGIN QUARTER 4" and not Text.StartsWith([Description], "THE GAME") and [Description] <> "TWO-MINUTE WARNING"),
#"Reordered Columns1" = Table.ReorderColumns(#"Filter Out Procedural Records",{"GameEventId", "GameId", "GameDate", "Quarter", "Minute", "Second", "OffenseTeam", "DefenseTeam", "Down", "ToGo", "YardLine", "Description", "", "SeriesFirstDown", "_1", "NextScore", "TeamWin", "_2", "_3", "SeasonYear", "Yards", "Formation", "PlayType", "IsRush", "IsPass", "IsIncomplete", "IsTouchdown", "PassType", "IsSack", "IsChallenge", "IsChallengeReversed", "Challenger", "IsMeasurement", "IsInterception", "IsFumble", "IsPenalty", "IsTwoPointConversion", "IsTwoPointConversionSuccessful", "RushDirection", "YardLineFixed", "YardLineDirection", "IsPenaltyAccepted", "PenaltyTeam", "IsNoPlay", "PenaltyType", "PenaltyYards"}),
#"Removed Columns" = Table.RemoveColumns(#"Reordered Columns1",{"_1", "_2", "_3", "NextScore", "", "Challenger"}),
#"Reordered Columns2" = Table.ReorderColumns(#"Removed Columns",{"GameEventId", "GameId", "GameDate", "Quarter", "Minute", "Second", "OffenseTeam", "DefenseTeam", "Down", "ToGo", "YardLineDirection", "YardLine", "Description", "SeriesFirstDown", "TeamWin", "SeasonYear", "Yards", "Formation", "PlayType", "IsRush", "IsPass", "IsIncomplete", "IsTouchdown", "PassType", "IsSack", "IsChallenge", "IsChallengeReversed", "IsMeasurement", "IsInterception", "IsFumble", "IsPenalty", "IsTwoPointConversion", "IsTwoPointConversionSuccessful", "RushDirection", "YardLineFixed", "IsPenaltyAccepted", "PenaltyTeam", "IsNoPlay", "PenaltyType", "PenaltyYards"})

在#“重新排序的 Columns2”中

错误发生在这里:

#"Filter Out Game / End of Game" = Table.SelectRows(#"Replaced Bad Q4 End", each ([Description] <> "END GAME" and [Description] <> "GAME")),
#"Create GameEventId" = Table.AddColumn(#"Filter Out Game / End of Game", "GameEventId", each Number.ToText([GameId])&if [OffenseTeam] = null and Text.Start([Description],7) = "Timeout" then "TO" else [OffenseTeam]&"_"&Number.ToText([Quarter])&"."&Number.ToText([Minute])&"."&Number.ToText([Second])),

它与每个有关吗?

标签: powerquerym

解决方案


推荐阅读