Skip to main content
Announcements
Qlik Community Office Hours, March 20th. Former Talend Community users, ask your questions live. SIGN UP
cancel
Showing results for 
Search instead for 
Did you mean: 
arngue
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
Øystein_Kolsrud
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

4 Replies
Øystein_Kolsrud
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"));
}
Øystein_Kolsrud
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);
Øystein_Kolsrud
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

MCastoro
Contributor II
Contributor II

Hi Yko

Your example is very useful, thanks.

I'm trying to export LabelExpression from master Items but, if the label contains a formula (for example ='Year ' & sCurrent_Year , the result is, for example  Year 2020.

Is there a method to retrieve the formula instead the result ?

Thanks