Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
jnickell
Helper V
Helper V

Using a variable for statement in PowerQuery Beta for SSIS

I'm trying to use the PowerQuery Beta for some SSIS packages.  I was curious if any one had used this, in particular the ability to set a PowerQuery equivalent to a variable.  I've "gotten" it to work if I use the simple method of declaring the full PowerQuery statement in the "Single Query Text" box.  However I'm unable to save a PowerQuery Statement to a string variable.  It get an evaluation error message.

 

Here's the query (just testing at this point)

 

 

let
    BaseDate = DateTime.LocalNow(),
    WeekStart = Date.AddDays(Date.StartOfWeek(BaseDate,1),7),
    PeriodList = List.Dates(DateTime.Date(WeekStart),Number.FromText("5"),#duration(Number.FromText("6")+1,0,0,0)),
    StartDates = Table.FromList(PeriodList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    EndDates = Table.AddColumn(StartDates,"EndDate",each Date.AddDays([Column1],Number.FromText("6")))
in
  EndDates

 

 

 

I get this error message when trying to save the Variable. I'm guessing I need to wrap the statement in something, but I don't know what that is.

 

 

TITLE: Expression Builder
------------------------------

Expression cannot be evaluated.

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%C2%AE%20Visual%20Studio%C2%AE&ProdVer=16.6.30204.135&Evtsrc=Microsoft.DataTransformationServices.Controls.TaskUIFramework.TaskUIFrameworkSR&EvtID=FailToEvaluateExpression&LinkId=20476

------------------------------
ADDITIONAL INFORMATION:

Attempt to parse the expression "let
    BaseDate = DateTime.LocalNow(),
    WeekStart = Date.AddDays(Date.StartOfWeek(BaseDate,1),7),
    PeriodList = List.Dates(DateTime.Date(WeekStart),Number.FromText("5"),#duration(Number.FromText("6")+1,0,0,0)),
    StartDates = Table.FromList(PeriodList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    EndDates = Table.AddColumn(StartDates,"EndDate",each Date.AddDays([Column1],Number.FromText("6")))
in
  EndDates" failed. The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed, or might be missing part of a required element such as a parenthesis.

 (Microsoft.DataTransformationServices.Controls)

 

 

 

The official page has nothing to help

https://docs.microsoft.com/en-us/sql/integration-services/data-flow/power-query-source?view=sql-serv...

5 REPLIES 5
rdeheld
Frequent Visitor

Hi Thanks for this I am struggeling with the same. I am trying to use a Bearer Token as a parameter for a web source. How should I implement the    @[User::Bearer] variable in this query?

Source = Json.Document(Web.Contents("https://api.sam360.com/api/Report/GetRecords?reportId=HardwareAllComputersGeneralDetails&organisatio...", [Headers=[Authorization= @[User::Bearer] , "Content-Type"="application/json; charset=utf-8"]])),





Based on my recent experience I think you'd wind up with something similar to:
The SSIS variable declaration is going to need to be broken into two different strings and concatenated with your user variable. 

The existing double quotes in Power Query, need to be escaped with a \. 

"
Source = Json.Document(Web.Contents(\"https://api.sam360.com/api/Report/GetRecords?reportId=HardwareAllComputersGeneralDetails&organisatio...\", [Headers=[Authorization="+@[User::Bearer]+" , \"Content-Type\"=\"application/json; charset=utf-8\"]])),
....
"

 

jnickell
Helper V
Helper V

I wound up coming back to this for a new project and believe I figured out what I needed to do to translate Power Query in Power BI to a SSIS variable.  Mainly documenting this for my future self.
The main thing is that any " characters need to be escaped and if you're using a variable inline, the string needs to be broken and concatenated with the variable using a + .  

 

Hope this is helpful to others. 

Original PQ sample

let
    Source = Folder.Files("C:\Users\me\Completed\"),
    #"Filtered Rows" = Table.SelectRows(Source, each ([Extension] = ".xml")),
    #"Filtered Hidden Files1" = Table.SelectRows(#"Filtered Rows", each [Attributes]?[Hidden]? <> true),
    #"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content])),
    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
in
    #"Renamed Columns1"

 

I used used Find & Replace in a text editor and then tweaked to include the variable I needed

"
let
    Source = Folder.Files(\"" + @[User::MyVariable] + "\"),
    #\"Filtered Rows\" = Table.SelectRows(Source, each ([Extension] = \".xml\")),
    #\"Filtered Hidden Files1\" = Table.SelectRows(#\"Filtered Rows\", each [Attributes]?[Hidden]? <> true),
    #\"Invoke Custom Function1\" = Table.AddColumn(#\"Filtered Hidden Files1\", \"Transform File\", each #\"Transform File\"([Content])),
    #\"Renamed Columns1\" = Table.RenameColumns(#\"Invoke Custom Function1\", {\"Name\", \"Source.Name\"}),
in
    #\"Renamed Columns1\"
"

 

 

 

v-eachen-msft
Community Support
Community Support

Hi @jnickell ,

 

Here is a blog about "Power Query Source for SQL Server Integration Services" for your reference:

https://www.mssqltips.com/sqlservertip/6305/power-query-source-for-sql-server-integration-services/

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

It looks like this article takes the same approach as others.  It requires a fully self contained power query statement.  It doesn't reference using the Power Query from a Variable approach.  

 

Sorry if there's a double post, the first one errored and it doesn't look like it saved it.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.