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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
golbarg
Frequent Visitor

Issues invoking custom function from another

Hello,

 

I'm having trouble finding what's wrong when invoking a custom function from another.

 

Consider:

 

/* getTimeEntryPage(updateFrom, page) */
(updateFrom as text, page as text) =>
let
    ...
in
    ...

 

 

This works as expected whan manually invoked with, for example: getTimeEntryPage("2021-03-24", "1").

 

Now, I also have this:

 

/* getTimeEntriesFromDate(updateFrom) */
(updateFrom as text) =>
let
    Source = Json.Document(Web.Contents(/*This query works*/)),
    List = {1..Source[total_pages]},
    #"Converted to Table" = Table.FromList(List, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "page"}}),
    #"Invoked Custom Function" = Table.AddColumn(#"Renamed Columns", "getTimeEntryPage", each getTimeEntryPage(updateFrom, [page])),
    ...
in
    ...

 

 

When I call getTimeEntriesFromDate("2021-03-24") manually, I get the following error:

"Unexpected error: Operation is not valid due to the current state of the object."

 

In the #"Invoked Custom Function" line, the following will work (although will only return a subset of data):

getTimeEntryPage(updateFrom, "1")

 

In the same line, the following will return the same error as above (expected as 1 is a number, not the expected text type):

getTimeEntryPage(updateFrom, 1)

 

Since [page] is set to text type, I don't understand why this is not working. Does anyone have an idea?

 

Note: I've made sure the origin data is clean.

 

Thanks!

1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

Hi @golbarg 

 

Are you sure it is the issue with [page]? Can you try to wrap Text.From([page]), see how it goes?

 #"Invoked Custom Function" = Table.AddColumn(#"Renamed Columns", "getTimeEntryPage", each getTimeEntryPage(updateFrom, Text.From([page])))

 

View solution in original post

3 REPLIES 3
Vera_33
Resident Rockstar
Resident Rockstar

Hi @golbarg 

 

Are you sure it is the issue with [page]? Can you try to wrap Text.From([page]), see how it goes?

 #"Invoked Custom Function" = Table.AddColumn(#"Renamed Columns", "getTimeEntryPage", each getTimeEntryPage(updateFrom, Text.From([page])))

 

Hey @Vera_33,

 

Wow, that was easier than expected, it worked, thanks!

 

Any idea why I need to convert a text value to text? It feels wrong.

Hi @golbarg 

 

No, it does not seem to be needed to convert a text to text...I tried to replicate your case with a simple custom function and a list of numbers, it worked after the column changed to text, did not occur the issue...maybe you should have a look at your custom function getTimeEntryPage

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.