cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAC scripting to filter WBS Top members where measure BC (Costs) > 0 and Blank (BW Live Connection)

RajuRao
Participant
0 Kudos
165

Hello Experts,

I am working in SAP Analytics Cloud (SAC) with a BW Live Connection.
In my story, the main table (Table_1) contains dimension such as WBS along with the measure BaseCost.

My requirement is:
I want to automatically filter or select only those WBS  members where BaseCost > 0 and Blank using SAC scripting, without creating a flag or calculated field in the BW query.

I tried using getResultSet() and setDimensionFilter() as shown in SAP Community examples, but my script is not filtering correctly when BaseCost is zero and Blank. I have given below the script what I used.

Could you help with script for this type of requirement (measure-based dimension filtering in BW live model)?
Also, please confirm whether this kind of filtering in scripting affects performance for around 30 WBS members.

Thank you,
Raju

 

// Get data source from the table
var ds = Table_1.getDataSource();

// Get the visible result set (only the displayed members)
var rs = ds.getResultSet();

// Create a typed array to hold the filtered WBS IDs
var wbsList = ArrayUtils.create(Type.string);

// Loop through each visible row
for (var i = 0; i < rs.length; i++) {
var row = rs[i];
var wbs = row["WBS"];
var baseCost = row["BaseCost"];

if (wbs && wbs.id && baseCost && baseCost.formattedValue) {
var val = baseCost.formattedValue;

// keep if BaseCost > 0 or blank ("-")
if (val === "-" || Number(val) > 0) {
wbsList.push(wbs.id);
}
}
}

// Apply the filter if list is not empty
if (wbsList.length > 0) {
ds.setDimensionFilter("WBS", wbsList);
} else {
ds.removeDimensionFilter("WBS");
}

// optional: check in console
console.log(wbsList);

Accepted Solutions (0)

Answers (0)