PowerQueryNet

repository·master·Indexed 42 days ago

https://github.com/gsimardnet/powerquerynet

A tool and .NET library for executing Power Query M formulas from the command line or within C# applications. Includes the PQNet CLI for running .pq, .pbix, and .xlsx files with support for exporting results to CSV, JSON, HTML, XML, or SQL Server.

Tokens
1.1K
Snippets
6
Records
6
Agent score
3%

What's inside PowerQueryNet

  1. Install PowerQueryNet

    master

    To use PowerQueryNet, download and install the MSI installer.

    Important Dependency: You must download PowerQuerySdk.vsix (version 1.0.0.16) and place it in the same folder as PowerQueryNet.msi before running the installer. Failure to do this may result in an incomplete installation.

    Download: https://github.com/gsimardnet/PowerQueryNet/releases/latest/download/PowerQueryNet.msi
    Dependency: http://dakahn.gallery.vsassets.io/_apis/public/gallery/publisher/dakahn/extension/powerquerysdk/1.0.0.16/assetbyname/PowerQuerySdk.vsix
  2. Run a 'Hello World' M formula via PQNet CLI

    master

    To verify your installation, create a simple M script and run it via the CLI.

    1. Create a file named helloworld.pq with the following content:
    let Source = "Hello, World!" in Source
    1. Execute it in the Command Prompt:
    pqnet helloworld.pq
    pqnet helloworld.pq
  3. Use PowerQueryNet in .NET (C#)

    master

    To integrate Power Query execution into your C# application, add a reference to the PowerQueryNet.Client library.

    You can use the Query class to define your M formula and the PowerQueryCommand class to execute it. The ExecuteOutputFlags property allows you to specify the desired output format (e.g., ExecuteOutputFlags.Csv).

    var qry = new Query { Formula = "let hw = \"Hello World\" in hw" };
    var pqc = new PowerQueryCommand() { ExecuteOutputFlags = ExecuteOutputFlags.Csv };
    var result = pqc.Execute(qry);
  4. Use the PQNet CLI to run M formulas

    master

    PQNet is the Command Line Interface included with PowerQueryNet. It allows you to execute Power Query M formulas and export results to various formats or databases.

    Export to file formats

    You can export query results to csv, json, html, or xml using the -o flag.

    pqnet "#Hello World.pq" -o json

    Export to SQL Server

    Use the -s flag to provide a connection string and the -t flag to specify the target table.

    pqnet "#Hello World.pq" -s "Data Source=.\SQL2016;Initial Catalog=AdventureWorks2012;Integrated Security=SSPI" -t "dbo.HelloWorld"

    Run queries from a Power BI (.pbix) file

    You can extract results from a specific query within a .pbix file using the -o (output format) and -f (file path) flags.

    pqnet MyReport.pbix Query1 -o csv -f result.csv
    pqnet "#Hello World.pq" -o json
  5. Use the PQNet CLI to run Power Query files and reports

    master

    The PQNet command-line tool allows you to execute .pq (Power Query) files or report files (like .pbix or .xlsx) using specific transformation functions or parameters.

    Basic Usage

    To run a Power Query file with a specific function:

    PQNet "filename.pq" functionName

    Running with Credentials and Output Formats

    You can specify a credentials file, an output format, and a destination file path:

    • -c: Path to a credentials XML file.
    • -o: Output format (csv, html, json, or xml).
    • -f: Destination file path.

    Example for CSV output:

    PQNet "AdventureWorksSales.pq" -c "#credentials.xml" -o csv -f "%temp%\AdventureWorksSales.csv"

    Running with Report Files (.pbix, .xlsx)

    You can pass report files and additional arguments such as connection strings or transformation types:

    • -s: Data source connection string.
    • -t: Transformation type.
    • -a: Additional flag (e.g., dc).

    Example for a PBIX file:

    PQNet "..\MyFiles\MyReport.pbix" vChineseCalendar -s "Data Source=.\SQL2016;Initial Catalog=master;Integrated Security=True" -t tChineseCalendar -a dc
    PQNet "AdventureWorksSales.pq" -c "#credentials.xml" -o csv -f "%temp%\AdventureWorksSales.csv"