Skip to content

Db2 for i and Power BI: IBM i data in a data warehouse and BI reports

B2Bnetwork team · · 6 min

IBM i, RPG and mainframe

In brief

Data from Db2 for i reaches Power BI in three ways: directly through the IBM Db2 connector and an on-premises data gateway, through a data warehouse loaded overnight, or through change data capture from the database journal. A direct connection is enough for a few reports, while a warehouse is better when there are many reports or the data is combined with other systems. Whichever you choose, you need to fix dates stored as numbers, CCSID 65535 fields and codes without lookup tables, ideally in SQL views on IBM i.

Three paths from IBM i to reports

PathHow it worksWhen to choose itRisk
Power BI directlythe IBM Db2 connector in Import or DirectQuery mode, through an on-premises data gatewaya few reports, data from one systemload on production, report logic scattered across Power BI files
A warehouse loaded overnighta job copies data from views into the warehouse, Power BI reads the warehousemany reports, data from several systemsdata from the previous day, separate infrastructure
Change data capture (CDC)changes read from the database journal flow into the warehouse or a streamdata needed within minutes, large tablesjournal configuration, more components to maintain

The choice depends on the number of reports, the number of source systems and how fresh the data has to be. When a warehouse pays off for a mid-sized company is covered in A data warehouse for a mid-sized company.

Connecting Power BI to Db2 for i step by step

The IBM Db2 connector in Power BI uses the Microsoft driver by default, which connects over the DRDA protocol. According to Microsoft's documentation, the IBM Db2 driver for .NET, available as an option in Power BI Desktop, does not work with IBM i. Steps:

  1. Database name. On IBM i, the DSPRDBDIRE command shows the relational database directory. The entry with the remote location *LOCAL is the name to enter as the database.
  2. Port. The default DRDA port is 446. Check the service entry with WRKSRVTBLE and that the port is listening with NETSTAT.
  3. Data gateway. The Power BI service refreshes data from IBM i through an on-premises data gateway installed on a server in the company network. The IBM Db2 connector requires a gateway regardless of where the database runs.
  4. SQL packages. On the first connection, the connector creates a package in the NULLID collection. If the user lacks the authority to do so, SQLCODE -805 and -551 errors appear. The IBM i administrator can grant authority to the CRTSQLPKG command for the first connection and revoke it afterwards.
  5. A profile for reporting. A separate user profile with read access to the reporting views, no screen access and no special authorities.

Data you need to fix along the way

A database on IBM i often remembers the days when dates were stored as numbers and only the program's author knew what a field meant. A report built straight on such files shows numbers, but not information. The most common fixes:

ProblemExampleFix in an SQL view
A date stored as a numberDECIMAL(7,0) in CYYMMDD format, e.g. 1251130conversion to the DATE type, handling zeros and 9999999
A CCSID 65535 fieldPower BI shows hexadecimal strings instead of texta cast to text with the correct CCSID
Trailing spacesa customer name followed by 20 spacesRTRIM in the view
Codes without lookup tablesstatus "3", document type "FZ"a join to a lookup table or a CASE with a description
Logically deleted recordsa status field set to "U" instead of deletinga condition in the view
Multi-member filesdata from different years in separate members of one filean SQL alias for each member, or merging them

Make these fixes once, in SQL views on IBM i with long, readable column names, rather than separately in every Power BI report. Then the warehouse, Excel and Power BI all calculate the same way. Describing tables in SQL instead of DDS is covered in Db2 for i: SQL instead of DDS.

Production load and refresh

Every query from Power BI runs on IBM i as a database server job and uses the same disks and memory as the application. Therefore:

  • Import mode with refreshes outside the night batch window puts a predictable load on the system, once or a few times a day;
  • DirectQuery mode sends a query on every click in the report, so it needs indexes for the report's filters and a sensible number of users;
  • large tables (document lines from many years) are loaded incrementally, by change date, not in full on every refresh.

How to find the queries that load the system is covered in AS/400 performance tuning.

A warehouse and change data capture

As reports multiply and IBM i data has to be combined with the CRM, the web shop or the HR system, it is better to feed a warehouse. The simplest option is an overnight load from the views. When the data is needed within minutes, changes are read from the database journal: the tables must be journaled, and a change data capture tool, such as the Debezium connector for IBM i, passes them on. The technique is described in Change data capture.

Every number in a report should have a reconciliation rule against the source system: the monthly invoice total in the report equals the total from the RPG program that prints the register. Without that, the first discrepancy undermines trust in the whole report, as When ERP reports do not add up shows. The reporting data layer, the semantic model in Power BI and data quality checks are the scope of Data and reporting. How to plan the Power BI rollout itself is covered in Implementing Power BI.

Questions and answers

Can Power BI connect to AS/400 without additional software?

The IBM Db2 connector is built into Power BI and uses the Microsoft driver by default, so you do not need to install an IBM driver in Power BI Desktop. To refresh in the Power BI service, you need an on-premises data gateway on a server in the company network. On the IBM i side, you need the database name, the DRDA port and a profile with read access.

Import or DirectQuery for IBM i data?

Usually Import. Data refreshed a few times a day is enough for most reports, and the load on the system is predictable. DirectQuery makes sense when a report has to show the current state, such as stock levels, and only with views that have indexes for the report's filters.

Why does Power BI show strange characters instead of text from IBM i?

Most often the field has CCSID 65535, meaning it is tagged as binary data, and the driver does not translate it to text. The fix is an SQL view that casts the field to text with the correct CCSID, or changing the field's tag in the database after checking that it will not break RPG programs.

Will BI reports slow down the IBM i system?

They can, if they query production often and without indexes. Import mode with refreshes outside the night batch, incremental loads of large tables and views with the right indexes all help. With many reports, it is better to feed a warehouse and take the load off IBM i entirely.

Developing a system on IBM i or mainframe? Talk to an RPG engineer.

Let's talk

Read more: IBM i, RPG and mainframe

All in IBM i, RPG and mainframe →