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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
AnViL999
Frequent Visitor

Retrieve conditional formatting rules

In which object are the rules stored that I created through the fx button? I want to apply those rules to the dataset that was returned by the wildcardselector. I wasn't able to find them in the DataView object

 

help is much appreciated

6 REPLIES 6
AnViL12
Frequent Visitor

Thanks to this topic i was able to fix it:
https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Conditional-Formatting-createDa...

Thanks for the help, much appreciated

dm-p
Super User
Super User

Hi @AnViL999,

 

The rules aren't accessible to the visual as the main window handles them; you only get the resulting value from the evaluated rules as in the appropriate location in the data view objects. MS does not expose more data from a report than a visual technically needs access to, so if you want the rules, you'll need to create an idea for it and hope that MS doesn't have any privacy concerns with supplying this information to a custom visual data view and is prepared to supply them. The alternative is to take the path other vendors have taken: add appropriate data roles and mappings for any dependent measures and handle the UI and logic for conditional formatting internally.

 

Regards,

 

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




AnViL999
Frequent Visitor

Hello @dm-p  , 

Based on what you said I updated my capabilities.json file.

 

Whenever I select a subset that starts with a value that meets the rule the color changes. If not the default color is applied. What do I need to add in my update statement of somewhere else. So that for each dataPoint the rule is being evaluated and the correct color is being added?

 

For some reason I cannot correctly format the code:

 

private renderMap(): void {
        const width = this.target.clientWidth;
        const height = this.target.clientHeight;
   
        const projection = d3.geoMercator()
            .center([5.5, 52])
            .scale(Math.min(width, height) * 10)
            .translate([width / 2, height / 2]);
   
        const path = d3.geoPath().projection(projection);
   
        // Clear existing content
        this.baseMapGroup.selectAll("*").remove();
        this.dynamicLayerGroup.selectAll("*").remove();
   
        // Render base map (if you have base map data)
        if (this.geojsonData && this.geojsonData.features) {
            this.baseMapGroup.selectAll(".province")
                .data(this.geojsonData.features)
                .enter().append("path")
                .attr("class", "province")
                .attr("d", path as any)
                .attr("fill", "#FBF5E7")
                .attr("stroke", "#CCCCBE")
                .attr("stroke-width", 1);
        }
   
        // Render dynamic layer (polygons from LineString)
        this.dynamicLayerGroup.selectAll(".custom-polygon")
            .data(this.polygonGeoJSONs)
            .enter().append("path")
            .attr("class", "custom-polygon")
            .attr("d", path as any)
            .attr("fill", "none")
            .attr("stroke", (d, i) => this.colorDataPoints[i].color)
            .attr("stroke-width", 3);
   
        console.log(`Rendered ${this.polygonGeoJSONs.length} polygons`);
    }
 

 

Hi @AnViL999,

 

If you are now adding the value as a measure in the data view, it should be a case of retrieving it from the relevant location, assigning it to your view model, and performing the necessary logic there. I might approach this by:

  1. Testing to see if a field matching that data role is present in the data view
  2. When assigning a value, assign the extracted value first (based on this role if flagged as present), with a fallback to the property value

However, where this will be depends on your data view and data role configuration, which isn't available in the above code. This snippet is presumably from your view model, which assumes you've already mapped it and doesn't give me any details on its lineage. As such, it would be good to know your dataRoles and dataViewMappings configuration, and the relevant parts of your mapping logic for your view model where you are trying to access it.

 

If you are still using conditional formatting after making capabilities changes and expect things to coexist somehow, then your formatting model logic will also need to be considered. Similarly, if you are using data-bound properties with a view to subbing in a measure. In that case, this further complicates analysis, as these are in different places in the data view depending on what selectors you are using and the type of data view mapping you have. In these cases it may be easier to make your entire visual available (or a suitable portion of it) as a resource that can be checked out and built/developed locally, with some example data and expected outcomes, as this will help diagnose and hopefully solve.

 

Cheers,

 

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




AnViL12
Frequent Visitor

To add to my reply below:

and of course to have a default value if no filter is applied...

AnViL999
Frequent Visitor

Hello @dm-p ,

 

Thank you for your reply.

I have sent you a private message with the source code.
It also contains a sample data set. What I am trying to achieve and which is partly working is showing the polygons, filtering based on the ID and showing the polygon based on if the Values column has the value 1. What I am now trying to achieve is to have a conditional formatting rule based on the Color_Rule column. For example 1 = green, 2 = blue, 3 = red. The conditional formatting part doesn't work...  the color_rule column isn't mapped to the Values measure but on another column in the power bi dataset

kind regards,

AnViL

 

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors