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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ingeborg
Frequent Visitor

Power Query: FomulaFirewall with Invoked Custom Function

I have imported a CSV-file into Power BI and in Power Query I get one column from this file's table and try to run an API-function on the new table, resulting in this error:

Formula.Firewall: Query 'orgnr' (step 'Invoked Custom Function') references other queries or steps, so it may not directly access a data source. Please rebuild this data combination.

Import csv into table CSVfil

I import the CSV with this code (*** = private info):

 

 

 

let
    Source = Csv.Document(Web.Contents("https://***.sharepoint.com/***/Datatabeller/Enhetstabellene/Alle-orgnr/" & "20-01-23_enheter_alle.csv"),[Delimiter=";", Encoding=65001]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each ([Forretningsadresse.landkode] = "NO")),
    #"Filtered Rows1" = Table.SelectRows(#"Filtered Rows", each Text.StartsWith([Forretningsadresse.kommunenummer], "3"))
in
    #"Filtered Rows1"

 

 

 

Then I make a new query, and run a function on that query. This throws an error.

Start a new table with on of the columns

The table CSVfil have many columns I don't need. So I extract only one of the columns into a new query/table called orgnr.

 

 

 

let
    Source = Table.SelectColumns(CSVfil,{"Organisasjonsnummer"})
in
    Source

 

 

 

When invoking the function, I get the error.

I read this blogpost and tries to do the extra stage/step

https://www.excelguru.ca/blog/2015/03/11/power-query-errors-please-rebuild-this-data-combination/

 

 

 

let
    Source = orgnr,
    #"Invoked Custom Function" = Table.AddColumn(Source, "funkFirma2", each funkFirma2([Organisasjonsnummer]))
in
    #"Invoked Custom Function"

 

 

 

And then I tried to run the function. But then I get the error.

Turning the Privacy settings to ignore solves the error. But that is not a good solution. It was suggested in this video:

https://www.youtube.com/watch?v=l4b8yRUpaoM

I have also tries changing the settings of each permission in File > Options and settings > Data source settings with no luck.

The function

The function get information from an API with this code:

 

 

 

let funkFirma2 = (orgnr as text) =>
    let
        Kilde = Xml.Tables(Web.Contents("https://www.vismabizweb.no/soap/BizwebPartner.asmx/hentFirma2?brukernavn=***&passord=***&orgnr=" & orgnr & "&med_bransjer=true&med_kontakt_personer=true"))

    in
        Kilde
    
in 
    funkFirma2

 

 

 

How can I get rid of the error and make the function work, without risking terrible stuff with the privacy setting too low?

9 REPLIES 9
ingeborg
Frequent Visitor

I have imported a CSV-file into Power BI and in Power Query I get one column from this file's table and try to run an API-function on the new table, resulting in this error:

Formula.Firewall: Query 'orgnr' (step 'Invoked Custom Function') references other queries or steps, so it may not directly access a data source. Please rebuild this data combination.

Import csv into table CSVfil

I import the CSV with this code (*** = private info):

 

let
    Source = Csv.Document(Web.Contents("https://***.sharepoint.com/***/Datatabeller/Enhetstabellene/Alle-orgnr/" & "20-01-23_enheter_alle.csv"),[Delimiter=";", Encoding=65001]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each ([Forretningsadresse.landkode] = "NO")),
    #"Filtered Rows1" = Table.SelectRows(#"Filtered Rows", each Text.StartsWith([Forretningsadresse.kommunenummer], "3"))
in
    #"Filtered Rows1"

 

Then I make a new query, and run a function on that query. This throws an error.

Start a new table with on of the columns

The table CSVfil have many columns I don't need. So I extract only one of the columns into a new query/table called orgnr.

 

let
    Source = Table.SelectColumns(CSVfil,{"Organisasjonsnummer"})
in
    Source

 

When invoking the function, I get the error.

I read this blogpost and tries to do the extra stage/step

https://www.excelguru.ca/blog/2015/03/11/power-query-errors-please-rebuild-this-data-combination/

 

let
    Source = orgnr,
    #"Invoked Custom Function" = Table.AddColumn(Source, "funkFirma2", each funkFirma2([Organisasjonsnummer]))
in
    #"Invoked Custom Function"

 

And then I tried to run the function. But then I get the error.

Turning the Privacy settings to ignore solves the error. But that is not a good solution. It was suggested in this video:

https://www.youtube.com/watch?v=l4b8yRUpaoM

I have also tries changing the settings of each permission in File > Options and settings > Data source settings with no luck.

The function

The function get information from an API with this code:

 

let funkFirma2 = (orgnr as text) =>
    let
        Kilde = Xml.Tables(Web.Contents("https://www.vismabizweb.no/soap/BizwebPartner.asmx/hentFirma2?brukernavn=***&passord=***&orgnr=" & orgnr & "&med_bransjer=true&med_kontakt_personer=true"))

    in
        Kilde
    
in 
    funkFirma2

 

How can I get rid of the error and make the function work, without risking terrible stuff with the privacy setting too low?

Hi @ingeborg ,

 

Could you please try to use the Table.Buffer function?

 

let
    Source = Table.SelectColumns(CSVfil,{"Organisasjonsnummer"}),
    Keep = Table.Buffer(Source)
in
    Keep


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Jimmy801
Community Champion
Community Champion

Hello @ingeborg 

have you been able to solve the problem with the replies given?

If so, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

All the best

Jimmy

Hi @ingeborg  

sometimes it helps to convert the staging query into a function (without any parameters) instead.

 

So this would be:

 

() =>
let
    Source = Csv.Document(Web.Contents("https://***.sharepoint.com/***/Datatabeller/Enhetstabellene/Alle-orgnr/" & "20-01-23_enheter_alle.csv"),[Delimiter=";", Encoding=65001]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each ([Forretningsadresse.landkode] = "NO")),
    #"Filtered Rows1" = Table.SelectRows(#"Filtered Rows", each Text.StartsWith([Forretningsadresse.kommunenummer], "3"))
in
    #"Filtered Rows1"

and then you can call it like so in the subsequent query like so:

 

let
    Source = Table.SelectColumns(CSVfil(),{"Organisasjonsnummer"})
in
    Source

  or maybe its even this query that has to be turned into a function, just try it out.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Jimmy801
Community Champion
Community Champion

Hello @ingeborg 

 

you need to have the csv-query as well as the query, the invokes the data-source-function in one query

so this should work out for you

let
    Source = Csv.Document(Web.Contents("https://***.sharepoint.com/***/Datatabeller/Enhetstabellene/Alle-orgnr/" & "20-01-23_enheter_alle.csv"),[Delimiter=";", Encoding=65001]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each ([Forretningsadresse.landkode] = "NO")),
    #"Filtered Rows1" = Table.SelectRows(#"Filtered Rows", each Text.StartsWith([Forretningsadresse.kommunenummer], "3")),
    #"Invoked Custom Function" = Table.AddColumn(#"Filtered Rows1", "funkFirma2", each funkFirma2([Organisasjonsnummer]))
in
    #"Invoked Custom Function"

 

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Thank you!

But I need to run several different functions (API) on the same numbers (Organisasjonsnummer), so I need to be able to do this in different queries.

 

I know I may right-click and make a new query from a column, but then the it's connected to the source-csv directly and I need to connect it to the filtered table.

Hello @ingeborg 

 

how about using this central query to apply all APIs needed?

Did you try to disable the firewall-function? (File -> Options & settings -> Options -> privacy -> Ignore privacy level)


If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Yes, but I'm afraid of the consequences,

 

Turning the Privacy settings to ignore solves the error. But that is not a good solution. It was suggested in this video:

https://www.youtube.com/watch?v=l4b8yRUpaoM

I have also tries changing the settings of each permission in File > Options and settings > Data source settings with no luck.

Hello @ingeborg 

 

so the only solution is to put everything in one query

 

Jimmy

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors