Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Naveen2
Contributor II
Contributor II

Read data from Hypercube in .Net SDK

Hi,

We are using the standard .NET SDK to read data from a Hypercube. We are able to read data and save it in a variable of type Qlik.Engine.NxDataPage using the below code shared in screenshot.

We would like to convert this data to a JSON format or if that is not possible we would like to convert the data into a list. But we are unable to read the contents of the variable and change it into native data format of C#.

Many thanks for your help in advance.

Labels (2)
1 Solution

Accepted Solutions
Øystein_Kolsrud
Employee
Employee

The definition of the NxDataPage class can be found here: https://help.qlik.com/en-US/sense-developer/February2019/apis/net+sdk/html/T_Qlik_Engine_NxDataPage....

It contains a property "Matrix" that is a list of "NxCellRows" (one for each page in the list of pages used when requesting data). "NxCellRows" is in turn just defined as "List<NxCell>". Typically you only send one page when getting data though, and in that case you would just take the firs one. If you want to do something for all rows, then you usually do something like this:

foreach (var row in theData.Matrix.Single())
{
    DoSomethingWithRow(row);
}

Now the "NxCell" type definition can be found here: https://help.qlik.com/en-US/sense-developer/February2019/apis/net+sdk/html/T_Qlik_Engine_NxCell.htm

It contains quite a few properties, but the two most important ones are "Num" and "Text". Which one you would use to access the data depends on the type of the columns of the hypercube. From the screenshot, it looks like you have been using the hypercube example. Have a look at this row:

https://github.com/kolsrud/qlik-dot-net-sdk-hypercube-usage/blob/master/HypercubeUsage/Program.cs#L1...

It shows how to handle data from a hypercube where each row contains two strings and one number.

View solution in original post

5 Replies
Øystein_Kolsrud
Employee
Employee

The definition of the NxDataPage class can be found here: https://help.qlik.com/en-US/sense-developer/February2019/apis/net+sdk/html/T_Qlik_Engine_NxDataPage....

It contains a property "Matrix" that is a list of "NxCellRows" (one for each page in the list of pages used when requesting data). "NxCellRows" is in turn just defined as "List<NxCell>". Typically you only send one page when getting data though, and in that case you would just take the firs one. If you want to do something for all rows, then you usually do something like this:

foreach (var row in theData.Matrix.Single())
{
    DoSomethingWithRow(row);
}

Now the "NxCell" type definition can be found here: https://help.qlik.com/en-US/sense-developer/February2019/apis/net+sdk/html/T_Qlik_Engine_NxCell.htm

It contains quite a few properties, but the two most important ones are "Num" and "Text". Which one you would use to access the data depends on the type of the columns of the hypercube. From the screenshot, it looks like you have been using the hypercube example. Have a look at this row:

https://github.com/kolsrud/qlik-dot-net-sdk-hypercube-usage/blob/master/HypercubeUsage/Program.cs#L1...

It shows how to handle data from a hypercube where each row contains two strings and one number.

Naveen2
Contributor II
Contributor II
Author

Hi Yko,

Thank You for your response. It helped us read the data from an Hypercube. 

We are using the hypercube example you mentioned, but this has an example to create an application using load script and then creating an hypercube from this application.

I am trying to read an existing Qliksense application and then create a hypercube on top of it.

I explored the below possibility.

I try to read an application using app Traverse class and then pass this as an argument to create an Hypercube, but I get an error. The reason for the error is Hypercube method use IApp and Traverse class uses IApp Identifier.

So, how can we create an Hypercube (based on an existing application), in this example?

Regards,

Naveen P

Øystein_Kolsrud
Employee
Employee

Conceptually there is no real difference when it comes to creating hypercubes in existing applications compared to a session app that is used in that example. But I think I need some more detailed understanding of what you want to do to be able to help you. Are you trying to:

  1. Read a hypercube from an existing object?
  2. Modify a hypercube in an existing object?
  3. Create a new hypercube in an existing object?
  4. Create a new hypercube temporarily for doing calculations?
Naveen2
Contributor II
Contributor II
Author

Hi Yko,

Thanks again for your help!

We are trying to create a new hypercube, based on an existing application.

Regards,

Naveen

Øystein_Kolsrud
Employee
Employee

To connect to an existing app, you would do something like this (you need to know the ID of the app, you can get that from the url when you open it in a browser):

var appIdentifier = location.AppWithId(<ID of the app>);
using (var app = location.App(appIdentifier))
{
<do stuff with app> }

Once the app is open, there is no real difference between this scenario and the one in the hypercube example. If you want to create a temporary hypercube that exists only for the duration of the execution of your program, then you would use a session object like this:

https://github.com/kolsrud/qlik-dot-net-sdk-hypercube-usage/blob/master/HypercubeUsage/Program.cs#L4...

And then add a hypercube to the object like this:

https://github.com/kolsrud/qlik-dot-net-sdk-hypercube-usage/blob/master/HypercubeUsage/Program.cs#L5...

If you want to modify an existing client object and make persistent changes to the app, then you would first need to find the ID of the object you want to modify, then open that specific object like this:

var theObject = app.GetGenericObject(<the object ID>);

Then you can make changes to that object just like you can for the session object.