Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

Announcements
Coming your way, the Qlik Data Revolution Virtual Summit. October 27-29. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Contributor III
Contributor III

.Net SDK getting master measures and dimensions

Is it possible to get master measure expression? And also is it possible to update it programatically?

I'm attempting to create a small .net desktop application that connects to personal edition and downloads in a csv the master dimensions and master measures. Then edit the csv and upload it again applying the changes.

For now on I have this piece of code. I'm getting the measure title correctly but i cannot see how to get the measure expression neither know if is it possible to update it.

 

IEnumerable apps = location.GetAppIdentifiers();
foreach (IAppIdentifier appid in apps)
{
    if (appid.AppId == app_id)
    {
        IApp app = location.App(appid);
        Qlik.Sense.Client.IMeasureList measures = AppExtensions.GetMeasureList(app);
        IEnumerable items = measures.Layout.As().MeasureList.Items;

        foreach (MeasureObjectViewListContainer measure in items)
        {
              string measureName = measure.Data.Title;
        }
    }
}
Labels (3)
1 Solution

Accepted Solutions
Highlighted
Employee
Employee

The second way to do this is to open the measure and look directly in the properties. This is also the way you would need to go if you want to modify the measure. This code shows how to set the definition of the first measure:

var measureList = app.GetMeasureList();
var data = measureList.Layout.MeasureList.Items.First();
app.DestroyGenericSessionObject(measureList.Id);
var measure = app.GetMeasure(data.Info.Id);
using (measure.SuspendedLayout)
{
    Console.WriteLine(measure.Properties.MetaDef.Title + " : " + measure.Properties.Measure.Def);
    measure.Properties.Measure.Def = "Sum(Sales)";
}
Console.WriteLine(measure.Properties.MetaDef.Title + " : " + measure.Properties.Measure.Def);

View solution in original post

3 Replies
Highlighted
Employee
Employee

There are two ways to do this. If you only want to list the expressions, then I'd say the most efficient way is to add the expression to the data of the list object used to list the measures. You can do that like this:

var measureList = app.GetMeasureList();
// The properties of the measure list will be updated at the end of the using clause
using (measureList.SuspendedLayout)
{
    // Add the path to the measure definition to the data set.
    measureList.Properties.MeasureListDef.Data.Set("def", "/qMeasure/qDef");
}

foreach (var data in measureList.Layout.MeasureList.Items.Select(item => item.Data))
{
    // The measure definition is now accessible through the property "def".
    Console.WriteLine(data.Title + " : " + data.Get<string>("def"));
}
Highlighted
Employee
Employee

The second way to do this is to open the measure and look directly in the properties. This is also the way you would need to go if you want to modify the measure. This code shows how to set the definition of the first measure:

var measureList = app.GetMeasureList();
var data = measureList.Layout.MeasureList.Items.First();
app.DestroyGenericSessionObject(measureList.Id);
var measure = app.GetMeasure(data.Info.Id);
using (measure.SuspendedLayout)
{
    Console.WriteLine(measure.Properties.MetaDef.Title + " : " + measure.Properties.Measure.Def);
    measure.Properties.Measure.Def = "Sum(Sales)";
}
Console.WriteLine(measure.Properties.MetaDef.Title + " : " + measure.Properties.Measure.Def);

View solution in original post

Highlighted
Employee
Employee

A running example of how to use lists to access measure information can now be found here:

https://github.com/AptkQlik/PublicExamples/tree/master/Lists