lundi 15 janvier 2018

How to write an If/else statement for XPath with multiple cases

In Xpath I am trying to write an if/else statement in the form of:

If (statement1) then
    value = 1;
Else if (statement2) then
    value = 2;
Else if (statement3) then
    value = 3;
Else if (statement4) then
    value = 4;
Else
    value = 5;

I have seen solutions for a simple if/else statement, but I cannot convert both these solutions (Solution 1, Solution 2) to something that works for me.

To make matters worse I need to retrieve data from a SharePoint list (connected data source) for each of the 4 statements. There is a value for a metric, and a value I need to compare it to. Based on that I want to set a different field's (or calculated value) value. The 4 statements are basically increments on each other, e.g.: 1 --> if x > 0.8, 2 --> if x > 0.6, 3 --> if x > 0.4 etc. Based on in which "bucket" x falls a certain percentage of a score (also retrieved from connected data source) will be assigned.

Each statement looks like if value > incrementX then y * z, where each of the 4 values is from a connected data source.

Note that I am using calculated fields to show or hide certain data based on a selection of date and account, so I cannot refer to local fields. I have also tried to fix it by using action rules based on the value of the Value field but these rules do not trigger even with a condition of true(), as it seems they are not re-evaluated. I strongly feel I need an If statement to fix this, a different solution could possibly be showing or hiding 5 score fields based on the conditions, but as I have 10~15 scores to take care of this would be come very large and unsustainable.

In a previously built Excel prototype (with local data) I used the following logic formula to do this (which worked great): =IF(x<=VLOOKUP(..);score;IF(x<=VLOOKUP(..);0.8*score;IF(x<=VLOOKUP(..);0.6*score;IF(x<=VLOOKUP(..);0.4*score;0.2*score))))

TL;DR Please help me translate these solutions (Solution 1, Solution 2) to work with a bigger if/else statement.

Thank you kindly for your help!

Aucun commentaire:

Enregistrer un commentaire