Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
nhuzaa
Frequent Visitor

Filter a measure column using AdvanceFilter

I followed the steps on https://github.com/Microsoft/powerbi-visuals-sampleslicer However the columns I want to filter is a Measure not Grouping.

I came across IFilterMeasureTarget https://microsoft.github.io/powerbi-models/interfaces/models.ifiltermeasuretarget.html Tried the following

   callbacks.getAdvancedFilterColumnTarget = (): IFilterMeasureTarget=> {
            let valueCol: DataViewValueColumn= this.dataView.categorical.values[0];
            let target: IFilterMeasureTarget = {
                table: valueCol.source.queryName.substr(0,valueCol.source.queryName.indexOf('.')),
                measure: valueCol.source.queryName,
            };

            return target;
        };

But its not working

6 REPLIES 6
v-viig
Community Champion
Community Champion

We'd recommend to try to use BasicFilter instead of AdvancedFilter.

 

const basicFilter: models.IBasicFilter = {
  target: {
    table: "Products",
    column: "Version"
  },
  operator: "In",
  values: [
    1,
    2,
    3,
    4
  ]
};

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

nhuzaa
Frequent Visitor

  target: {
    table: "Products",
    column: "Version"
  },

What should be there for the table and column key for the measure columns ?

v-viig
Community Champion
Community Champion

We'd recommend to take a look at this code to figure out how to populate table and column name.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

nhuzaa
Frequent Visitor

I want to user

IFilterMeasureTarget not IFilterColumnTarget because I want to filter the measure not the category. How do i get the measure and table values. Approach I am following is below  but its not working

 let target: IFilterMeasureTarget = {
                table: valueCol.source.queryName.substr(0,valueCol.source.queryName.indexOf('.')),
                measure: valueCol.source.queryName,
            };

 What is the correct approach to get the
table and measure value

v-viig
Community Champion
Community Champion

I'll check it out and get back.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

v-viig
Community Champion
Community Champion

It seems you can use column target instead of measure.

Have you tried such solution?

 

const min: number = 100;
const max: number = 101;

if (!this.dataView) {
    return;
}

const source = this.dataView.categorical.values[0].source;

let conditions: IAdvancedFilterCondition[] = [];

if (min) {
    conditions.push({
        operator: "GreaterThan",
        value: min
    });
}

if (max) {
    conditions.push({
        operator: "LessThan",
        value: max
    });
}

const query: string[] = /\((\w+).(\w+)\)/.exec(source.queryName);

let target: IFilterColumnTarget = {
    table: query[1],
    column: query[2],
};

let filter: IAdvancedFilter = new window['powerbi-models'].AdvancedFilter(target, "And", conditions);
this.host.applyJsonFilter(filter, "general", "filter", FilterAction.merge);

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors