Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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;
}
}
}
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);
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"));
}
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);
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
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