Justin Unverricht
02/11/2022, 6:08 AMDan Homola
02/11/2022, 1:18 PMimport {
bucketMeasure,
IInsight,
modifyPopMeasure,
newBucket,
insightBucket,
insightSetBuckets,
isPoPMeasure,
} from "@gooddata/sdk-model";
const originalInsight: IInsight = {} as any; // skipped for brevity
// get both measures, we assume the insight is a Headline
const primaryMeasureBucket = insightBucket(originalInsight, "measures");
const secondaryMeasureBucket = insightBucket(originalInsight, "secondary_measures");
const primaryMeasure = bucketMeasure(primaryMeasureBucket);
const secondaryMeasure = bucketMeasure(secondaryMeasureBucket);
// use a different primary measure
const swapedPrimaryMeasure = primaryMeasure; // or some custom logic to get the new primary measure, skipped for brevity
// if the secondary measure is a PoP measure, make sure the new one points to the new primary measure
const adaptedSecondaryMeasure = isPoPMeasure(secondaryMeasure)
? modifyPopMeasure(secondaryMeasure, (m) => m.masterMeasure(swapedPrimaryMeasure))
: secondaryMeasure;
// get new insight with the buckets updated
const newInsight = insightSetBuckets(originalInsight, [
newBucket("measures", swapedPrimaryMeasure),
newBucket("secondary_measures", adaptedSecondaryMeasure),
]);
Is this something you were looking for or did I not understand you correctly?Justin Unverricht
02/14/2022, 11:12 PMDan Homola
02/15/2022, 8:10 AM