Forum Discussion

pankajsonkul's avatar
pankajsonkul
Helper I
9 years ago

Set custom filter values as 'blank' or null

Hi,

How to set value as blank to custom filter.

Following code which will create custom filter for blank value as null but it throws following error 

"values.0 is invalid. Not meeting type constraint"

 

code

custom visual code

var customFilter={
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: filters[1].target.table,
column: filters[1].target.column
},
operator: filters[1].operator ,
values:[null]
}

Currently we have requirement such that we have allready existing filter in report and we want merge new custom filter in existing filter. Existing filter value is null  for operator 'is not blank' so whenever we apply existing and new custom filter it will throws value invalid error.

 

So which value pass in custom filter so it will display as (Blank) in filter panel?

Thanks in Advance.

 

8 Replies

    • pankajsonkul's avatar
      pankajsonkul
      Helper I

      Thanks for reply,
      It will throws same error
      Following date filter,in which we have allready some date filter and 'Blank' filter whenever we read this filter values in code it will display below output
      $schema:"http://powerbi.com/product/schema#basic"
      operator:"NotIn"
      target:"object"
      column:"Date"
      table:"DateRange"
      __proto__:"object"
      values:Array(1)
      0:null
      length:1

      now whenever we add new value in this custom filter it will throws exception for null value.

      Existing filter screen shot 

      This existing filter values in this filter we want push new filter value like'Feb 2017' it will push but due to null value  it will throws error.Actually in filter pane it will display as '(Blank)' but in code this value is null.

      So how we can handle this null value.

       

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, we also need to able to set (Blank) in basic filters. is there any update regarding this?

  • dearwicker's avatar
    dearwicker
    Frequent Visitor

    You can do this by using an advanced filter with the IsBlank operator:

     

    new pbi.models.AdvancedFilter(
    { table, column }, "And", { operator: "IsBlank", value: "" }
    ).toJSON()

     

    The empty string for value shouldn't be necessary (after all, we are just checking if the column is blank, not comparing it with a value. But I get error messages if 'value' is omitted.

     

    The "And" operator is only there because of the perculiar way filters are composed: the above snippet is combining a list of operators which happens to only have one item in the list, so it won't actually use the And.