From ea9addaaf07a479fbe00e2c039f0a0220f7432a8 Mon Sep 17 00:00:00 2001
From: "James D. Bartlett III"
<37491308+JamesDBartlett3@users.noreply.github.com>
Date: Thu, 2 May 2024 13:38:03 -0500
Subject: [PATCH] Add TableFromDataflow function, useful for pulling tables
into Power BI from Power Platform Dataflows (#14)
---
Functions/Table/FromDataflow.pq | 87 +++++++++++++++++++++++++++++++++
M.pq | 2 +
2 files changed, 89 insertions(+)
create mode 100644 Functions/Table/FromDataflow.pq
diff --git a/Functions/Table/FromDataflow.pq b/Functions/Table/FromDataflow.pq
new file mode 100644
index 0000000..c69bc5c
--- /dev/null
+++ b/Functions/Table/FromDataflow.pq
@@ -0,0 +1,87 @@
+let
+ // Define metadata for the function, describing its purpose and usage.
+ metaDocumentation = type function (
+ WorkspaceNameOrID as (type text meta [
+ Documentation.FieldCaption = "Workspace Name or ID",
+ Documentation.SampleValues = {"MyWorkspace", "128fd147-7051-4f3f-95b7-7970f6209d5f"},
+ Formatting.IsMultiLine = false,
+ Formatting.IsCode = false
+ ]),
+ DataflowNameOrID as (type text meta [
+ Documentation.FieldCaption = "Dataflow Name or ID",
+ Documentation.SampleValues = {"MyDataflow", "127fd147-7051-4f3f-95b7-7970f6209d5e"},
+ Formatting.IsMultiLine = false,
+ Formatting.IsCode = false
+ ]),
+ TableName as (type text meta [
+ Documentation.FieldCaption = "Table Name",
+ Documentation.SampleValues = {"MyTable"},
+ Formatting.IsMultiLine = false,
+ Formatting.IsCode = false
+ ]),
+ optional RowLimit as (type number meta [
+ Documentation.FieldCaption = "Row Limit",
+ Documentation.LongDescription = "Enter the number of rows to return. Leave blank or select -1 to return all rows.",
+ Documentation.SampleValues = {null, -1, 0, 100, 1000, 10000, 1000000, 10000000, 1000000000},
+ Formatting.IsMultiLine = false,
+ Formatting.IsCode = false
+ ])
+ ) as any meta [
+ Documentation.Name = "TableFromDataflow",
+ Documentation.LongDescription =
+ //This is the description of the documentation, it only accepts a handful of HTML tags for formatting.
+ "
+
Table from Dataflow
+ Creator: James D. Bartlett III
+ LinkedIn: https://www.linkedin.com/in/jamesdbartlett3/
+ Blog: https://datavolume.xyz
+ GitHub: https://github.com/JamesDBartlett3
+ LinkedIn: https://linkedin.com/in/JamesDBartlett3
+ Mastodon: https://techhub.social/@JamesDBartlett3
+ Bluesky: https://bsky.app/profile/jamesdbartlett3.bsky.social
+
+ This function will return a table from a dataflow in a Power BI workspace, limited to a specified number of rows. All connection string components have been parameterized to make switching between data sources as simple and easy as possible.
+ Parameters:
+ WorkspaceNameOrID: The name or ID of the workspace containing the dataflow.
+ DataflowNameOrID: The name or ID of the dataflow containing the table.
+ TableName: The name of the table to return.
+ RowLimit: The number of rows to return. Leave blank or select -1 to return all rows.
+
+ References
+ Limit The Amount Of Data You Work With In Power BI Desktop Using Parameters And Deployment Pipelines (Chris Webb)
+ "
+ ],
+ // Define the main function
+ myFunction = (
+ WorkspaceNameOrID as text,
+ DataflowNameOrID as text,
+ TableName as text,
+ optional RowLimit as number
+ ) as table =>
+ let
+ // Set RowLimit to -1 if null
+ RowLimit = if RowLimit is null then -1 else RowLimit,
+ // Set the Source to Power Platform Dataflows
+ Source = PowerPlatform.Dataflows(null),
+ // Get the list of workspaces containing dataflows
+ WorkspaceList = Source{[Id = "Workspaces"]}[Data],
+ // Use try...otherwise to select the workspace by it name or ID
+ SelectedWorkspace =
+ try WorkspaceList{[workspaceName = WorkspaceNameOrID]}[Data]
+ otherwise WorkspaceList{[workspaceId = WorkspaceNameOrID]}[Data],
+ // Use try...otherwise to select the dataflow by its name or ID
+ SelectedDataflow =
+ try SelectedWorkspace{[dataflowName = DataflowNameOrID]}[Data]
+ otherwise SelectedWorkspace{[dataflowId = DataflowNameOrID]}[Data],
+ // Select the table by its name from the selected dataflow
+ SelectedTable = SelectedDataflow{[entity = TableName, version = ""]}[Data],
+ // Limit the number of rows returned
+ FilterLogic =
+ if RowLimit < 0
+ then SelectedTable
+ else Table.FirstN(SelectedTable, RowLimit)
+ in
+ FilterLogic
+in
+ // Apply the function metadata to myFunction.
+ Value.ReplaceType(myFunction, metaDocumentation)
diff --git a/M.pq b/M.pq
index c6f102a..2e46143 100644
--- a/M.pq
+++ b/M.pq
@@ -161,6 +161,7 @@ let
Number.ToText = Number.ToText,
Number.Type = Number.Type,
Order.Descending = Order.Descending,
+ PowerPlatform.Dataflows = PowerPlatform.Dataflows,
Record.Field = Record.Field,
Record.FieldNames = Record.FieldNames,
Record.FieldValues = Record.FieldValues,
@@ -177,6 +178,7 @@ let
Table.Distinct = Table.Distinct,
Table.DuplicateColumn = Table.DuplicateColumn,
Table.ExpandTableColumn = Table.ExpandTableColumn,
+ Table.FirstN = Table.FirstN,
Table.FromList = Table.FromList,
Table.FromRecords = Table.FromRecords,
Table.FromRows = Table.FromRows,