© 2015-2026. MindStreamAnalytics.com

How to Export Relational Data to a CSV File in OneStream

Adding a Button to Export XFC Table Data to CSV

Dim strLabelText As String = "Hello this is a bunch of text to" &vbCr & "illustrate a point about text wrapping"

In a prior Blog, “Creating a Dashboard to Display XFC Tables” I outlined how to create a dashboard that will display the contents of your applications XFC tables in a dashboard using a SQL Table Editor, this was based on a client request. The client, after seeing the dashboard, wanted to be able to export the data from the table to a CSV file. Yes, it’s possible to right click on a SQL Table editor and select export to CSV and it will export the data to a CSV File.

OneStream Dashboard XFC Tables

The issue with this approach is that a SQL Table Editor, for performance reasons, pages the data that is returned. For large data sets you can have many pages of data that are only retrieved once you navigate to that page in the SQL Table Editor. The right-click and export to CSV only exports the data for the tab that you are on.

OneStream XFC Format Example

So, what if your users want to export the Entire contents of the table, they have selected to a CSV file? There is a solution, there typically is in OneStream. This can be accomplished through a button and a Dashboard Extender.

Step 1. Add a button to your dashboard. In this screen shot I am adding a button to a dashboard that I created for a previous blog.

OneStream XFC Format Example

Step 2. Set the Button to run a Dashboard Extender, passing in the Parameter that holds the Table name selected from the Combo Box, as a name value pair.

OneStream XFC Format Example

Step 3. Create a Dashboard Extender that will Query the Application database for the Selected Table, get all the contents of that table, load it into a Data Table, then write the contents of that Data Table to a CSV file in the Application Database, accessible through File Explorer.

The next steps are all within the Dashboard Extender that you just created.

Step 4. Create a variable to hold the value of the Selected Table Name

'Get name of selected Table
Dim strTableName = args.NameValuePairs.XFGetValue("SelectedTable")

Step 5. You will need a SQL Query that uses the selected Table Name to return all the contents of the selected table to a Data Table.

'Create SQL Query that will get all the contents of the selected table
Dim sql As New System.Text.StringBuilder
sql.AppendLine($"
                SELECT * FROM {strTableName}
                ")
'Return the SQL table and load the contents into a Data Table in memory
Dim dt As new DataTable()
Using dbConnApp As DbConnInfo = BRApi.Database.CreateApplicationDBConnInfo(si)
    dt = BRApi.Database.ExecuteSql(dbConnApp, sql.ToString, False)
End Using

At this point you will now have a Data Table in Memory. The next step will be to write the contents of that Data Table to a CSV File. The code that I use will create multiple CSV files if there are more than one million records in the Data Table. In this case, this was done because the users were opening the CSV file in Excel, and I needed to take the row limitations of Excel into account.

Step 6. Define the CSV File Name and the File Path. In this case I am using the Table Name as the File Name. Note how I am defining the file path with the user’s name. The function si.UserName returns the user name with a space between the first and last name, this space needs to be stripped out as the application database file path does not have a space in it.

'Create the variables that will degine the export File name and Path
'Note home the file path includes the User Name and strips oout any spaces from the User Name
Dim strFileName As String = strTableName
Dim strFilePath As String = $"Documents/Users/{stringhelper.RemoveSystemCharacters(si.UserName,false,false)}"

Step 7. Create a String Builder object that will hold the contents of the Data Table. It is this object that will be used to create the CSV file. Then using append line, add the file header record to the String Builder using the Data Table Column Names. This is optional, depending on whether you want the header record in the CSV file or not.

'String Builder Object that will hold the contents of the Data Table that was populated from the SQL Table query
 Dim fileAsString As New System.Text.StringBuilder
 'Create the Header row for the export file based on the Column Names in the Data Table
 fileAsString.AppendLine(String.Join(","dt.Columns.Cast(Of DataColumn).Select(Function(x) x.ColumnName)))
 
 

Step 8. Now you need to loop through the contents of the Data Table and add them to the String Builder using the Item Array method of the Data Table. Appending each record to the String Builder with a comma between each field. A comma because we are building a CSV file, which is Comma Delimited.

OneStream XFC Format Example

'Loop through all the Data Table rows, appending them to the String Builder Object
For Each dr As DataRow In dt.Rows
fileAsString.AppendLine(String.Join(",",dr.ItemArray()))

Step 9. The final step is to write the contents of the String Builder to the Application Database, in the Users Folder. Note that in this example the write occurs either when the end of the Data Table is reached or if a Million Records has been reached (to manage file size). The write uses brapi.filesystem.insertorupdateFile. To use this function the String Builder needs to be converted to Byte then passed into a XFile object.

'Check to see if either a million records have been added to the String BUilder Object
'Or the end of the Data Table has been reached
'In either case the String Builder Object is written to the Application File FOlder using brapi.FileSystem.InserOrUpdateFile
'If the Data Table contains more than 1 million records the process creates a seperate CSV files for each group of a million
If (intY + 1) Mod 1000000 = 0 Or intY = dt.Rows.Count = 1 Then
Dim fileAsByte() As Byte = Sytem.Text.Encoding.Unicode.GetBytes(fileAsString.ToString)
                
Dim xfFileDataInfo As New XFFileInfor(fileSystemLocation.ApplicationDatabase,$"{strFileName}{intWriteCount}.csv",strFilePath)
Dim xFFileData As New XFFile(xfFileDataInfo,String.Empty,fileAsByte)
                
brapi.FileSystem.InsertOrUpdateFile(si,XfFileData)
                
intWriteCount = intWriteCount + 1
FileAsString.AppendLine(String.Join(",",dt.Columns.Cast(Of DataColumn).Select(Function(x) x.ColumnName)))
End If
             
intY = intY + 1   

The code in its entirety.


Public Function Export_XFC_Table_Data(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As DashboardExtenderArgs) as Object
Try

'Get name of selected Table
Dim strTableName = args.NameValuePairs.XFGetValue("SelectedTable")

'Create SQL Query that will get all the contents of the selected table
Dim sql As New System.Text.StringBuilder
sql.AppendLine($"
                SELECT * FROM {strTableName}
                ")
'Return the SQL table and load the contents into a Data Table in memory
Dim dt As new DataTable()
Using dbConnApp As DbConnInfo = BRApi.Database.CreateApplicationDBConnInfo(si)
    dt = BRApi.Database.ExecuteSql(dbConnApp, sql.ToString, False)
End Using
 
'String Builder Object that will hold the contents of the Data Table that was populaed from the SQL Table query
Dim fileAsString As New System.Text.StringBuilder
'Create the Header row for the export file based on the Column Names in the Data Table
fileAsString.AppendLine(String.Join(","dt.Columns.Cast(Of DataColumn).Select(Function(x) x.ColumnName)))
  
'Create the variables that will define the export File name and Path
'Note home the file path includes the User Name and strips oout any spaces from the User Name
Dim strFileName As String = strTableName
Dim strFilePath As String = $"Documents/Users/{stringhelper.RemoveSystemCharacters(si.UserName,false,false)}"

'String Builder Object that will hold the contents of the Data Table that was populaed from the SQL Table query
Dim fileAsString As New System.Text.StringBuilder
'Create the Header row for the export file based on the Column Names in the Data Table
fileAsString.AppendLine(String.Join(","dt.Columns.Cast(Of DataColumn).Select(Function(x) x.ColumnName)))
 
Dim intWriteCount As Integer = 1
Dim intY As Integer = 0
  
  
  
         For Each dr As DataRow In dt.Rows
             fileAsString.AppendLine(String.Join(",",dr.ItemArray()))
            'Check to see if either a million records have been added to the String Builder Object
            'Or the end of the Data Table has been reached
            'In either case the String Builder Object is written to the Application File Folder using brapi.FileSystem.InserOrUpdateFile
            'If the Data Table contains more than 1 million records the process creates a seperate CSV files for each group of a million
            If (intY + 1) Mod 1000000 = 0 Or intY = dt.Rows.Count = 1 Then
                Dim fileAsByte() As Byte = Sytem.Text.Encoding.Unicode.GetBytes(fileAsString.ToString)
                
                Dim xfFileDataInfo As New XFFileInfor(fileSystemLocation.ApplicationDatabase,$"{strFileName}{intWriteCount}.csv",strFilePath)
                Dim xFFileData As New XFFile(xfFileDataInfo,String.Empty,fileAsByte)
                
                brapi.FileSystem.InsertOrUpdateFile(si,XfFileData)
                
                intWriteCount = intWriteCount + 1
                FileAsString.AppendLine(String.Join(",",dt.Columns.Cast(Of DataColumn).Select(Function(x) x.ColumnName)))
             End If
             
             intY = intY + 1  
             
          Next 

 

Now when the Button on the Dashboard is clicked, the dashboard extender is executed and creates a CSV file in the Application Database Folder, under the Users folder. If the user then selects the file and clicks on the download file button (in File Explorer), the file will be downloaded to their local desktop.

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 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

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