PQ error

millhouse123

Active Member
Joined
Aug 22, 2006
Messages
335
I have a power query I am trying to add a custom function to but am getting an error and I am not sure how to resolve.


My query returns the data in the following format - 2 columns

Name(workbook Name), custom.name(worksheet Name)
1001000401_2018.xlsx, 1001000401
1001000401_2018.xlsx, 1001000401 - Alloc OH

<tbody>
</tbody><colgroup><col><col></colgroup>


I want to apply the function below which works fine when manually entering the parameter's but I get
the following error when I run it. Thanks in advance for your time.

An error occurred in the ‘’ query. Expression.Error: We cannot convert the value "1001000401" to type Number.
Details:
Value=1001000401
Type=Type


Note that I had to use the Number.ToText function in order for PQ to recognize the input values as strings. It works perfect when manually copy and pasting the workbook and worksheet names as long as I use the Number.ToText function. I have also stripped out all the intermediate steps from this function to troubleshoot.

Code:
(filename,wsname) =>
let
    Source = Excel.Workbook(File.Contents("F:\ExpAcct\Cost Study\2018 Time Study Forms\For Nick Testing\" & filename), null, true),
    #"PlaceHolder" = Source{[Item=Number.ToText(wsname),Kind="Sheet"]}[Data]
   in
    #"PlaceHolder"
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
If you want to ensure that function parameters are supplied as text, then you should specify the type in the function definition, like
Code:
(filename as text, wsname as text)

Before you use your function from your table, make sure to transform your table column types to text.

Now you no longer need Number.ToText.
 
Upvote 0

Forum statistics

Threads
1,216,737
Messages
6,132,436
Members
449,727
Latest member
Aby2024

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