PowerQuery syntax to append a string parameter

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
921
Office Version
  1. 365
Platform
  1. Windows
A simple named "ShipmentSource" Excel cell has a value.

I try to put it into a variable:
let shipmentsource = Excel.CurrentWorkbook(){[Name="ShipmentSource"]}[Content]{0},

I try to replace this kind of SQL lines
SQL:
/* RFQ Round */
DECLARE        @MyIntParameterValue int = 1

/* Shipment source */
DECLARE        @ShipmentSource nvarchar(50) = 'ThisIsMyShipmentSource'

with the content of ShipmentSource named cell:
Power Query:
/* Shipment source */#(lf)DECLARE#(tab)#(tab)
@ShipmentSource nvarchar(50) = '" & shipmentsource & "'#(lf)#(lf)

Result:
Power Query:
Expression.Error: We cannot apply operator & to types Text and Record.
Details:
    Operator=&
    Left=/* MyIntParameterValue */
DECLARE        @MyIntParameter int = 1

/* Shipment source */
DECLARE        @ShipmentSource nvarchar(50) = '
    Right=
        Column1=ThisIsMyShipmentSource

I could imagine this is very simple. And no, never before written a single line of PowerQuery code.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
This is not an answer, but It is easy. I can never remember the syntax and have just Googled this search 'powerquery to retrieve the value of a cell on a spreadsheet' and a number of options appeared.

HTH
 
Upvote 0
This is not an answer, but It is easy. I can never remember the syntax and have just Googled this search 'powerquery to retrieve the value of a cell on a spreadsheet' and a number of options appeared.

HTH

Otherwise I have this done, but the parsing into the SQL query doesn't seem to work. I can make a table and I can make a text field out of the value, but that's where I hit the wall.
 
Upvote 0
I decided to do something a lot simpler to start with and managed to do it:
Power Query:
let
    myCountry = Excel.CurrentWorkbook(){[Name="Ctry"]}[Content]{0}[Column1],
    Source = Sql.Database("thedatabaseinstance", "mydatabasename", [Query="select top 10 *#(lf)from country Where Name Like '" & Text.From(myCountry)  & "'"])
in
    Source

The important parts are that this myCountry comes from a single named cell. Not a table, just a named cell.
That "Text.From"-function was the key here to get it to work.
 
Upvote 0

Forum statistics

Threads
1,223,698
Messages
6,173,897
Members
452,536
Latest member
Chiz511

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top