© 2015-2024. MindStreamAnalytics.com

OneStream Blog - Joining Data Tables using Data Sets and Defined Relationships

Joining Data Tables using Data Sets and Defined Relationships

I’ve set up a lot of Dashboards containing Grid Views populated with a Data Adapter. With the Data Adapter being populated with data from a Relational Data Table. This is an easy way to expose the contents of relational data within a Dashboard. Filters can be applied, giving the users the ability to filter the data shown in the Grid View. Typically, I have done this using Combo Boxes or some other component that gives the Users a pick list of options that would then change a parameter value. With that parameter being used within the SQL statement that drives the Data Adapter. This has always been a straightforward process.

Behind the scenes the data adapter can do this either of two ways, using a Method Command Type or a SQL Command Type. The SQL command Type will run a SQL query directly against the relational source while the Method Query will call a data set business rule typically querying a relational source, then creating a VB.Net data table that is returned to the data adapter.

You are probably saying to yourself, “so far so good, I got this!”. However, what if you want to combine the results of 2 related data sources and return those through a single data adapter/grid view combination? You are probably saying “No Problem, its 2 relational sources, I’ll just use a join in the data query!”. Ok, now what if the business case changes and the 2 relational sources are in separate environments that can’t be accessed through a SQL Join? What if one is an application database table and the other is in an external database? In this case there is no easy way to create a SQL Join. Or even, I had this situation recently, one data source was a relational table, and the other was a Json returned data source from an external web API call. Now how are you going to join them?

VB.Net Datasets and defined relationships to the rescue. A Data Set can contain multiple tables and can contain defined relationships between those tables. With this you can query the Dataset, based on the defined relationship between those tables and return a single data table that holds those combined or joined data tables, or just some fields of data out of those data tables.

For this example, I am using 2 tables out of the application database, one of which is a custom table. However, I could just as easily query an external table using brapi.Database.CreateCustomExternalDbConnInfo.

Table 1 returns Accounts and their Descriptions from the internal Member Table.


SELECT MemberId, Name, Description, DimId FROM dbo.Member WHERE DimTypeId = '5' ORDER BY Name;

Table 2 returns data from a custom table.

What I want to do is join those 2 tables on the Name field in Table 1 and the Account field in Table 2 and return just Name, Description and Users to a Grid View (through a Data Adapter).

Desired Result:

So how do I do this?

1. Setup a Method Type Data Adapter that calls a Dashboard Data Set Business Rule.

2. Create the Dashboard Data Set Business Rule and in that Business Rule create your 2 source Data Tables.


'First Data Table
Dim dtMembers As New DataTable
Using dbConn As DBConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)
    Dim sql As New Text.StringBuilder
    sql.AppendLine($"SELECT MemberId, Name, Description, DimId FROM dbo.Member WHERE DimTypeId = '5' ORDER BY Name;")
    dtMembers = BRApi.Database.ExecuteSql(dbConn,sql.ToString,False)
Eng Using

'Second Tata Table
Dim dtMemberNames As New DataTable
Using dbConn As DBConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)
    Dim sql As New Text.StringBuilder
    sql.AppendLine($"SELECT Account, Users FROM dbo.XFC_Accounts_Users;")
    dtMemberNames = BRApi.Database.ExecuteSql(dbConn,sql.ToString,False)
Eng Using
    

3. Create the Data Tablet that will hold the joined results and be the return.


Dim dtResult As New DataTable
dtResult.Columns.Add("Name")
dtResult.Columns.Add("Description")
dtResult.Columns.Add(""Users)

4. Create the Data Set and add the source Data Tables to it.


'Data Set that holds the data tables
Dim dataSetMerged As New DataSet
dataSetMerged.Tables.Add(dtMembers)
dataSetMerged.Tables.Add(dtMemberNames)

5. Now define the relationship between the 2 tables. These are the fields from each data table that you will use to join the data on, think of it as being like a SQL Join.


Dim relation As New DataRelation("AccountNameRelation"),dataSetMerged.Tables(0).Columns("Name"),dataSetMerged.Tables(1).Columns("Account"),False)
dataSetMerged.Relations.Add(relation)

6. At this point you have a Data Set containing 2 Data Tables and a defined Relationship. The next step is to loop through the rows of one data table, getting the related rows from the second data table (based on the defined relationship) and add the desired fields as a row to your return data table.


' Loop through the rows of the on data table and get related "parent" rows based on the relationship
For Each childRow As DataRow In dtMemberNames.Rows
    Dim filterValue As String = childRow("Users").ToString()
    Dim parentRows As DataRow() = childRow.GetParentRows(relation)
    
    'Get the fields from each table that you want and add them to the return data table
    For Each parentRow As DataRow In parentRows
        dtResults.Rows.Add(parentRow("Name"),parentRow("Description"), childRow("Users"))
    Next
Next

Return dtResult

The code in its entirety.



Puiblic Function MergeDataTables(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As DashboardDataSetArgs) As DataTable

Try

'First Data Table
Dim dtMembers As New DataTable
Using dbConn As DBConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)
    Dim sql As New Text.StringBuilder
    sql.AppendLine($"SELECT MemberId, Name, Description, DimId FROM dbo.Member WHERE DimTypeId = '5' ORDER BY Name;")
    dtMembers = BRApi.Database.ExecuteSql(dbConn,sql.ToString,False)
Eng Using

'Second Tata Table
Dim dtMemberNames As New DataTable
Using dbConn As DBConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)
    Dim sql As New Text.StringBuilder
    sql.AppendLine($"SELECT Account, Users FROM dbo.XFC_Accounts_Users;")
    dtMemberNames = BRApi.Database.ExecuteSql(dbConn,sql.ToString,False)
Eng Using

Dim dtResult As New DataTable
dtResult.Columns.Add("Name")
dtResult.Columns.Add("Description")
dtResult.Columns.Add(""Users)

'Data Set that holds the data tables
Dim dataSetMerged As New DataSet
dataSetMerged.Tables.Add(dtMembers)
dataSetMerged.Tables.Add(dtMemberNames)

Dim relation As New DataRelation("AccountNameRelation"),dataSetMerged.Tables(0).Columns("Name"),dataSetMerged.Tables(1).Columns("Account"),False)
dataSetMerged.Relations.Add(relation)


' Loop through the rows of the on data table and get related "parent" rows based on the relationship
For Each childRow As DataRow In dtMemberNames.Rows
    Dim filterValue As String = childRow("Users").ToString()
    Dim parentRows As DataRow() = childRow.GetParentRows(relation)
    
    'Get the fields from each table that you want and add them to the return data table
    For Each parentRow As DataRow In parentRows
        dtResults.Rows.Add(parentRow("Name"),parentRow("Description"), childRow("Users"))
    Next
Next

Return dtResult

Catch ex As dtResult
    Throw ErrorHandler.LogWrite(si, New XFException(si,ex))
End Try
End Function

The result, when run through a data adapter, shows 2 fields from Table 1 and 1 field from Table 2!

This is powerful functionality that can be used when you need to join related data sources and can’t use a SQL Join.

Partner SpotLight

OneStream aligns to your business needs and changes more quickly and easily than any other product by offering one platform and one model for all financial CPM solutions. OneStream XF employs Guided Workflows, validations and flexible mapping to deliver data quality confidence for all collections and analysis while reducing risk throughout the entire auditable financial process.

OneStream Profile

Our Company

MindStream Analytics' senior staff was there at the birth of Business Intelligence. We have been part of building Business Intelligence nationally from its humble niche product status to the ubiquitous analytic tool that it is today. MindStream consultants are well versed in reporting and information management and are ready to help you leverage the power of multiple tier-1vendors. From Oracle Hyperion to IBM Cognos, we can help you select and integrate the right tools for you to better understand your information. MindStream Analytics has experience across a wide variety of industries: Business Services, Consumer Products, Energy, Financial Services, Healthcare, Manufacturing, Transportation , and Telecommunication. We have the depth and breadth of experience to help you deliver actionable information to users.

Whether you need an enterprise wide Oracle BI Enterprise Edition (OBIEE) rollout, an Oracle BI Apps rollout, or an IBM Cognos ReportNet rollout, MindStream Analytics is here to help you succeed.

Case Studies

Accumen

Thanks to the intervention of MindStream Analytics, Accumen's Finance department can now model their business with a new, more organized structure that isn't conventionally available in NetSuite.

Acme Brick

Acme Brick turned to MindStream Analytics for help implementing OneStream to replace their outdated TM1 solution.

Alterra

Alterra sought the expertise of MindStream to address the challenges they faced in their Capital Planning process.

ATCO Group

Energy conglomerate ATCO operates worldwide in utilities, power generation, and related services.

Avalon

Working with MindStream Analytics, Avalon Healthcare Solutions adopts NetSuite Planning and Budgeting to accelerate budgeting and forecasting processes.

Bayer Health Care

Bayer Healthcare implemented Hyperion Planning and Workforce Planning in 10 weeks to dramatically streamline their Income Statement budget and Workforce Planning process..

BluEarth

MindStream Analytics' partnership with BluEarth Renewables epitomizes the power of technology and collaboration.

Celgene

An Oracle Hyperion Planning Upgrade provides multi-national organization Hyperion Application optimization and stabilization.

Cleaver Brooks

OneStream XF was chosen as the platform that would transform Cleaver-Brooks' Finance processes.

CoorsTek

The collaboration between CoorsTek and MindStream resulted in significant improvements in CoorsTek's financial consolidation and reporting processes.

Elite Body Sculpture

MindStream Analytics' collaboration with Elite Body Sculpture encapsulates the transformative potential of targeted tech solutions in streamlining administrative processes.

Enlyte

Enlyte, a merger of Mitchell, Genex, and Coventry, faced challenges with disparate financial solutions and the need for combined reporting.

Flanders

MindStream Analytics collaborated with Flanders to implement OneStream Consolidation and Reporting solution.

Foley Products

Foley Products was facing a significant challenge with its Excel-based actual management reporting system.

Harte Hanks

The collaboration between MindStream Analytics and Harte Hanks culminated in a highly customized, user-friendly NetSuite implementation.

Interface

Interface used a complex, manual, excel-based FP&A process for monthly review, and the summary data was loaded in OneStream.

Kymera International

Thanks to Mindstream Analytics' assistance, Kymera was able to load all of their data into OneStream and validate it successfully.

MacLean Fogg

MacLean-Fogg partnered with MindStream, a leading implementor specializing in modernizing and optimizing enterprise systems.

MEPPI

MindStream's expertise and experience were sought to conduct a vendor selection initiative focusing on MEPPI's F2023 planning process.

OUAI

MindStream Analytics and OUAI's collaboration showcases the transformative power of strategic technological intervention.

Plaskolite

By migrating to OneStream, Plaskolite has achieved a material reduction in consolidation time and overall Financial Close cycle, eliminated the hours spent compiling and verifying data in Excel, streamlined its Planning, Budgeting and Forecasting model and delivered flexible and timely reporting that enables more strategic analysis of their financial data.

Redwire

Understanding the nuances of Redwire's challenges, MindStream Analytics devised a holistic approach to overcome them. The implementation of NetSuite was just the beginning.

Simon

Simon's existing corporate Hyperion Financial Management (HFM) production application was consolidating at a rate of seven hours, a performance issue causing great headache to corporate Accounting.

Source Code

The successful transition to OneStream revolutionized Source Code's financial reporting.

Subway

Subway collaborated with MindStream Analytics for the NetSuite Analytics Warehouse implementation.

UPenn

MindStream Consulting and AppCare team members are proud be working side by side with UPenn university in accomplishing this implementation and along with continuing our AppCare services after go-live.

USG

USG was an Oracle Hyperion customer realizing that it needed more specialized support for its various Oracle Hyperion applications.

Vantiv

Dividing a hyperion planning application, expanding the hyperion footprint to forecast on the business? Customer categories.

Versant Health

Versant Health engaged MindStream to help resolve the challenges they were experiencing with their consolidation, close, and financial reporting processes.

Virginia Spaceport Authority

The MindStream team implemented the Standard + Workforce NetSuite Planning & Budgeting.

WeWork

MindStream Analytics determined that the best solution was to implement Oracle Essbase Cloud as part of the Oracle Analytics Cloud (OAC) platform-as-a-service

WindStream

Innovative use of essbase to streamline and connect hyperion financial management for enhanced financial analysis.

XY Planning

MindStream Analytics, well-versed in addressing such challenges, presented a comprehensive Netsuite solution for XY Planning.

Related Links