Power BI is a powerful and popular business intelligence tool that enables users to analyze data and share insights. Power Query is one of the most important features of Power BI, allowing users to connect to and transform data from a variety of sources. MarkLogic is an enterprise NoSQL database that is designed for handling unstructured data, such as documents, images, and videos. In this article, we will explore how to connect to a MarkLogic data source from inside Power BI using Power Query M language code.

Understanding the MarkLogic Data Source


Before we begin, it’s important to understand the structure of a MarkLogic data source. MarkLogic stores data as documents, which can be organized into collections. Each document has a unique URI (Uniform Resource Identifier) that can be used to retrieve it from the database. Documents can be in XML, JSON, or other formats, and can have a variety of schemas or no schema at all.

Installing the MarkLogic ODBC Driver

The first step in connecting to a MarkLogic data source from Power BI is to install the MarkLogic ODBC driver. This driver enables ODBC-compliant applications, such as Power Query, to connect to MarkLogic. You can download the driver from the MarkLogic website and follow the installation instructions.

Creating a New Query in Power BI

Once the ODBC driver is installed, you can create a new query in Power BI by selecting the “Get Data” option from the Home tab of the ribbon and choosing “ODBC” as the data source.

In the “ODBC” dialog box, you can select the MarkLogic ODBC driver and enter the necessary connection information, including the hostname, port, database name, user name, and password. You can also specify additional connection options, such as SSL encryption and certificate validation.

Writing Power Query M Language Code


After you have established a connection to the MarkLogic data source, you can begin writing Power Query M language code to retrieve and transform data. Power Query M language is a functional language that is used to manipulate data within Power Query.

To retrieve data from MarkLogic, you can use the ODBC.DataSource function, which takes the connection details as arguments and returns a table of data. For example, the following code retrieves all documents from a collection called “mycollection”:


Source = ODBC.DataSource(“dsn=MarkLogicDSN;UID=myuser;PWD=mypassword;Server=myserver;Database=mydatabase;Port=8000;SSLMode=require”),

mycollection = Source{[Name=”mycollection”]}[Data]



This code creates a data source using the ODBC.DataSource function and then filters the data to only include documents from the “mycollection” collection.

You can also use the Power Query M language to transform the data that you retrieve from MarkLogic. For example, you can use the Table.SelectColumns function to select only specific columns, or the Table.RenameColumns function to rename columns.


Connecting to a MarkLogic data source from inside Power BI using Power Query M language code is a powerful way to access and analyze unstructured data. By following the steps outlined in this article, you can establish a connection to a MarkLogic data source and retrieve and transform data using the Power Query M language.

Power BI Training Courses by G Com Solutions (0800 998 9248)

Contact Us


    Your Name (required)


    Email (required)


    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)

    Similar Posts