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.
Hello experts,
I was experimenting with the ability to run javascript inside power query. The idea came to me from this blog post https://www.thebiccountant.com/2018/04/25/regex-in-power-bi-and-power-query-in-excel-with-java-scrip... .
Huge thanks to @ImkeF for sharing this awesome idea.
I wanted to see if it is possible to run any other js in PQWRY.
For e.g. the way to convert the js part of the html
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Statements</h2>
<p>A <b>JavaScript program</b> is a list of <b>statements</b> to be executed by a computer.</p>
<p id="demo"></p>
<script>
x = 5; // Statement 2
y = 6; // Statement 3
z = x * y; // Statement 4
z1 = "The value of z is " + z + ".";
document.write(z1);
</script>
</body>
</html>
in a parameterized PQWRY would be
let
fx=(a,b)=>
Web.Page(
"<script>
x = "&a&";
y= "&b&";
z= x*y;
z1 = ""The value of z is "" + z + ""."";
document.write(z1);
</script>") [Data]{0}[Children]{0}[Children]{1}[Text]{0}
/*Data = fx{0}[Data],
Children = Data{0}[Children],
Children1 = Children{1}[Children]*/
in
fx
A complete example is below
let
xy=let
fx=(a,b)=>
Web.Page(
"<script>
x = "&a&";
y= "&b&";
z= x*y;
z1 = ""The value of z is "" + z + ""."";
document.write(z1)
</script>") [Data]{0}[Children]{0}[Children]{1}[Text]{0}
/*Data = fx{0}[Data],
Children = Data{0}[Children],
Children1 = Children{1}[Children]*/
in
fx,
Source = Table.FromColumns({{10..20},{30..40}}),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each xy([Column1],[Column2]))
in
#"Added Custom"
I was completely stunned to see that the js executed inside PQWRY and gave me the following result in DESKTOP
Column1 | Column2 | Custom |
10 | 30 | The value of z is 300. |
11 | 31 | The value of z is 341. |
12 | 32 | The value of z is 384. |
13 | 33 | The value of z is 429. |
14 | 34 | The value of z is 476. |
15 | 35 | The value of z is 525. |
16 | 36 | The value of z is 576. |
17 | 37 | The value of z is 629. |
18 | 38 | The value of z is 684. |
19 | 39 | The value of z is 741. |
20 | 40 | The value of z is 800. |
But the same query fails in dataflow and generates the following error
Expression.Error: The module named 'Html' has been disabled in this context
I want to be able to run js inside dataflow not only just inside desktop.
Does anyone know how to debug this error in DF?
I have barely scratched the surface. If possible, by running js inside DF we can unleash a massive amount of powerful data wrangling/extraction tasks such as regex, combinatorics to name a few.
I currently do all my combinatiorics work using R script but R does not run in DF which is a huge inconvenience. But if I can run js in DF I can bypass R altogether for tasks with a fully equivalent js.
Thank you in advance.
Solved! Go to Solution.
Referred to this https://docs.microsoft.com/en-us/power-bi/transform-model/dataflows/dataflows-features-limitations#d... that mentions Using the Web.Page connector requires a gateway.
I set up a gateway and it started working.
Referred to this https://docs.microsoft.com/en-us/power-bi/transform-model/dataflows/dataflows-features-limitations#d... that mentions Using the Web.Page connector requires a gateway.
I set up a gateway and it started working.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.