Forum Discussion

Coltsbro's avatar
Coltsbro
Frequent Visitor
9 years ago
Solved

Construct Filter with Javascript function

Hi all,   I am currently working on bringing Power BI Embedded to a place that our company can think of using this more often. One limitation I can currently see is potentially needing different fi...
  • Eric_Zhang's avatar
    9 years ago

    Coltsbro

    Below code works in my test. You can debug your filter by using the alert statement before applying it. Check more details on Filters. By the way, do note that when using "In", it is values and when other operators it is a scalar value. You may have to put more logics in your function.

    var arr = [1,2,3,4,6,8]
    
    function advancedFilter(table, column, logicalOperator, operator, value){
        
        if (logicalOperator === undefined) {
            logicalOperator = "And";
        }
        if (operator === undefined) {
            operator = "Is";
        }
        if (value === undefined) {
            value = 0;
        }
    
        return filter = {
            $schema: "http://powerbi.com/product/schema#advanced",
            target: {
                table: table,
                column: column
            },
            //logicalOperator: logicalOperator,
            //conditions: [
            //    {
                    operator: operator,
    //It is "values" when using a operator "In" values: value // } //] }; } alert(JSON.stringify(advancedFilter("table","column","","In",arr)));