R0b0tn1k
R0b0tn1k

Reputation: 4306

PowerBI PowerQuery: Token In expected

I'm looking at this example, and this should work: https://www.simple-talk.com/sql/reporting-services/power-query-formula-language-in-power-bi-desktop/

However, i'm getting a "Token In expected" error.

Here's the code:

let
    #"Datasource" = let
    Source = Sql.Databases("111.111.111.111"),
    DSN = Source{[Name="DSN"]}[Data],
    #"dbo_Datasource" = DSN{[Schema="dbo",Item="Datasource"]}[Data],
    BlockFilter = Table.SelectRows(#"dbo_Datasource", each ([block] <> "")),
    AddColQTR = Table.AddColumn(BlockFilter , "Start_Of_QTR", each Date.StartOfQuarter(DateTime.LocalNow()))
in
   AddColQTR

Upvotes: 1

Views: 14753

Answers (2)

Eduardo Contreras
Eduardo Contreras

Reputation: 1

The Token In Expected Error is rendered when you do not include a comma at the end of a step in Powerquery/Power BI, so you must add it. However, in your case you started with the hashtag "#" when it is not necessary. Connections are the first automated action and a subsequent action or step begins with the # not at the first step, the default connection line. Note also, that "" follow a #, (double quotes needed as to give an option of use of spaces between two words).

let
Source = 
Csv.Document(File.Contents("C:\Users\edcon\Documents\watchlists\value\ 
Value_Wed Sep 18 2024 (1).csv"),[Delimiter=",", Columns=10, 
Encoding=65001, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, 
[PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers", 
{{"Symbol", type text}, {"Last Price", Currency.Type}, {"Change $", type 
number}, {"Change %", type number}, {"Bid", type text}, {"Ask", type 
text}, {"Day's Range", type text}, {"52 Week Range", type text}, 
{"Volume", Int64.Type}, {"Last Trade (ET)", type text}})
in
#"Changed Type"`

Also, you should try to follow correct syntax on the add columns line.

ColQtr = Table.AddColumn(BlockFilter, "Start_of_Quarter", each
    if [enter method/function for if [date (use name of date column in 
        brackets]) is in quarter one, then january 1,
    if [enter method/function for if date is in quarter two, then april 1, 
        etc..
in ColQtr

Upvotes: 0

MarcelBeug
MarcelBeug

Reputation: 2967

You have 2x "let" and 1 "in"; each "let" should have a corresponding "in".

It looks to me that you should remove the line: #"Datasource" = let

Upvotes: 9

Related Questions