• Resolved jqaush8

    (@jqaush8)


    Hey I see in your documentation that the plugin supports filtering. I’m wondering where I put the filter code to make it work?

Viewing 1 replies (of 1 total)
  • Hey! Sorry for missing this initially! My team at Atlas maintains this plugin.

    The short version is that you’ll need add a function to your functions.php to do it. (There’s also an easy javascript way to do this if you’re comfortable with that–see my post on the power bi forums)

    First, you need to find the appropriate hook. This one, for example, when the nav menu is created. (You might want page load)

    For the nav menu case, for example, you can first add this filter to your functions.php:
    add_filter( 'wp_nav_menu_objects', 'append_power_bi_filters', 10, 2 );

    Then, you’ll need to create the function the filter references. If the page you wanted to apply filters to was, say, example.com/reports/sales and you wanted to filter the State table column SalesState to just Illinois, here’s how you’d format the function: (inputs surrounded by <carats> — don’t include the carats when you use this)

    function append_power_bi_filters( $items, $args ) {
    	foreach ($items as &$item) {
            // check if link begins with '#'
            $urlParts = explode('/',parse_url($item->url, PHP_URL_PATH));
    		if ($urlParts[1] == 'reports' and $urlParts[1] == 'sales' ){
    			$item->url =  $item->url . "?filters=%5B%7B%22%24schema%22%3A%22http%3A%2F%2Fpowerbi.com%2Fproduct%2Fschema%23basic%22%2C%22target%22%3A%7B%22table%22%3A%22<State>%22%2C%22column%22%3A%22<SalesState>%22%7D%2C%22operator%22%3A%22%3D%22%2C%22values%22%3A%5B%22<Illinois>%22%5D%7D%5D";
    		}
            }
    }

    As you can see, you can set values for the table, column, and value you’re interested in.

    There’s a lot of complexity you can add from here, like changing the referenced value or column based on what’s in the URL.

    Good luck and let me know if you have any questions.

    Peter

    • This reply was modified 4 years, 3 months ago by peterbenzoni.
Viewing 1 replies (of 1 total)
  • The topic ‘Filtering’ is closed to new replies.