Thursday 25 January 2018

Power BI - Bookmarking feature update (December 2017)

Case
In an earlier post we explained and showed you how to use the new bookmarking feature (October 2017 update) through an example combining a chart and related information of this chart. Besides that, you can also use bookmarks to switch between two charts in the same area in your report page. Unfortunately, this had its limitations: passing filters and multiple toggles. What has changed in the bookmarking functionality that makes it more user-friendly to use?

Bookmark updates December 2017











Old situation
Shortly after the release in October, we implemented bookmarks at our customer. We used two different charts in the same area in a report page to let our users look at the data from two perspectives, without making a new page or report. This is one of the great benefits of using bookmarking.

Unfortunately we quickly realize that this is a nice added functionality, but still has its limitations. In this post we will show you two examples: the passing of selected filters to another bookmark and multiple toggle buttons in one page.

Example 1: passing of selected filters
The selected filter in one bookmark doesn't work on the other bookmark when you switch from chart. If you select year 2016 in the first bookmark (with the first chart) and clicking on the button for the other bookmark (the second chart), the second chart will show all the data instead of only 2016.

Old - Filters not applying other bookmarks












Example 2: multiple toggle buttons
Multiple buttons in one report page to switch between charts doesn't work. When you have two toggle buttons (left and right area) where you want to switch charts: clicking toggle button number two on the right also effects the button (and the chart) on the left.

Old - Multiple toggle buttons doesn't work










Solution
As mentioned before, there are some updates related to the bookmark feature. These will solve the two examples in the old situation we described earlier. With this update, they also give you the ability to create a bookmark with a cross-highlighting state of your report. Before, cross-highlighting was not included as part of a bookmark and you could only save the entire state of a report (without selected filters, selected bar in a chart etc.). Now everything that is in your report can be saved as a part of a bookmark.

For now we will focus on solving the problems in the two examples described earlier about filtering and multiple toggle buttons in one report page.

Create the Report (images)
First, make sure you have the latest Power BI Desktop version. If you are using Power BI Desktop from the Microsoft Store, it updates automatically. Otherwise you can download the latest version of Power BI Desktop here.

The starting point in both reports is the same report from an earlier post. In example 1 we created a new chart on the same spot in the left corner of the chart 'Total Sales and Profit per Month'. We added a toggle button above the chart where you can switch between those two charts. In example 2 on a new report page we also added a new chart on in the right upper corner of the chart 'Total Sales and Profit per State'. We also use a toggle button here. Now we have have two toggle buttons on the same report page.

We created the toggle buttons by our own using Google images and then customized them with Paint.NET. For the text before the buttons, we used the custom visual 'Long Text Viewer'. You can download it here (it is not available in the store).

Result example 1
With this update you now have three categories of types of stuff to save in a bookmark: data (slicers, filters, cross-highlighting etc.), display (hiding visual, spotlight etc.) and current page (which page is related to the bookmark). You can turn these categories on and off by the settings of a bookmark.

New - Turn items on and off













To fix the problem from example 1, you have to uncheck the data category for both bookmarks (charts) which are involved with the toggle button. Now it only effects the buttons and the charts.

New - Selected filters effects other bookmark













Result example 2
Besides those new three categories, there is another option available: Selected Visuals (default is All Visuals). You will find this option below the categories.

New - Selected visuals

To fix the problem from example 2, we use this Selected Visuals. As said before, by default it will bookmark the entire page, but now you can select the visuals (charts, buttons etc.) that you want to include in the bookmark. First, we select all the visuals related to the left toggle button (black and off). You need to repeat this for the left toggle button, but now for all the visuals when this button is on (grey). Repeat this for the toggle button on the right and by the end there are four bookmarks. Do not forget to configure 'Link' in each bookmark for making both buttons work. Finally, select Selected Visuals for all those four bookmarks. To be clear: it seems simple, but it is meticulous work!

Below you will find the making of this solution.


NOTE:
By creating a bookmark with Selected Visuals, note the following:
  • Make sure you do not have a bookmark selected when creating a new one. Otherwise it will overwrite this bookmark with the new selected visuals. You can only deselect the bookmark by making an image visible/hidden.
  • After creating the bookmark with selected visuals, you cannot see which visuals are related to this bookmark. They are no longer marked in gray. 
  • You cannot give the visuals a name. In case of multiple toggle buttons you have at least four times a visual called 'image'. By place them in order you can distinguish them.  
You can download the entire Power BI report with all the examples here.

Conclusion
In this post you saw how the new updates related to the bookmark feature gives you more flexibility to creating bookmarks. Not all the technical changes are difficult (check or uncheck), but this is a huge update that will eliminates uncertainties and confusion among our users.

Unfortunately, there are still some updates needed to make it more user friendly to build/maintain the bookmarks. For example the opportunity to give the visuals a name or show which visuals are related to a bookmark (in case of selected visuals).

If you want more information about creating bookmarks in the first place (the basic), click here.

Monday 1 January 2018

Pause everything on your Azure playground - Tags

Case
To prevent unnecessary high bills because I forgot to turn off services, I want to pause everything in my Azure 'playground' subscription. However I want to give my co-workers more control to decide which machines and services they don't want to pause each night. Your current solution works with a centralized exception list that needs to be maintained by someone. Is there an alternative solution?
Pause everything v2
















Solution
You should of course make some agreements about being careful with pricey services, but you can support that with a 'simple' technical solution: run a PowerShell script in Azure Automation Runbook that pauses all often used services each night. In this version of the script, exceptions are handled with tags that people can add to their own server or service. Here is how you can add a tag to for example Azure Analysis Services.
Add tags to your service or server


















For this example we will pause the following Azure parts:
  • Azure Virtual Machines (not classics)
  • Azure SQL Data Warehouses
  • Azure Analysis Services
This is not a complete list, but once you understand these three, it should be relatively easy to add more services. Still to hard? Add a comment to suggest more services.

1) Automation Account
First we need an Azure Automation Account to run the Runbook with PowerShell code. If you don't have one or want to create a new one, then search for Automation under Monitoring + Management and give it a suitable name like 'maintenance', then select your subscription, resource group and location. For this example I will choose West Europe since I'm from the Netherlands. Keep 'Create Azure Run As account' on Yes. We need it in the code. See step 3 for more details.
Azure Automation Account














2) Credentials
Next step is to create Credentials to run this runbook with. This works very similar to the Credentials in SQL Server Management Studio. Go to the Azure Automation Account and click on Credentials in the menu. Then click on Add New Credentials. You could just use your own Azure credentials, but the best options is to use a service account with a non-expiring password. Otherwise you need to change this regularly.
Create new credentials

























3) Connections
This step is for your information only and to understand the code. Under Connections you will find a default connection named 'AzureRunAsConnection' that contains information about the Azure environment, like the tendant id and the subscription id. To prevent hardcoded connection details we will retrieve these fields in the PowerShell code.
Azure Connections
























4) Modules
The Azure Analysis Services methods (cmdlets) are in a separate PowerShell module which is not included by default. If you do not add this module you will get errors telling you that the method is not recognized. See below for more details.
The term 'Get-AzureRmAnalysisServicesServer' is not recognized
as the name of a cmdlet, function, script file, or operable program.














Go to the Modules page and check whether you see AzureRM.AnalysisServices in the list. If not then use the 'Browse gallery' button to add it, but first add AzureRM.Profile because the Analysis module will ask for it. Adding the modules could take a few minutes!
Add modules














5) Runbooks
Now it is time to add a new Azure Runbook for the PowerShell code. Click on Runbooks and then add a new runbook (There are also several example runbooks of which AzureAutomationTutorialScript could be useful as an example). Give your new Runbook a suitable name like 'PauseEverything' and choose PowerShell as type.
Add Azure Runbook















6) Edit Script
After clicking Create in the previous step the editor will be opened. When editing an existing Runbook you need to click on the Edit button to edit the code. You can copy and paste the code below to your editor. Study the green comments to understand the code. Notice that this version doesn't use Runbook variables.
Edit the PowerShell code














# PowerShell code
# Connect to a connection to get TenantId and SubscriptionId
$Connection = Get-AutomationConnection -Name "AzureRunAsConnection"
$TenantId = $Connection.TenantId
$SubscriptionId = $Connection.SubscriptionId
  
# Get the service principal credentials connected to the automation account. 
$null = $SPCredential = Get-AutomationPSCredential -Name "Administrator"

# Login to Azure ($null is to prevent output, since Out-Null doesn't work in Azure)
Write-Output "Login to Azure using automation account 'Administrator'."
$null = Login-AzureRmAccount -TenantId $TenantId -SubscriptionId $SubscriptionId -Credential $SPCredential
  
# Select the correct subscription
Write-Output "Selecting subscription '$($SubscriptionId)'."
$null = Select-AzureRmSubscription -SubscriptionID $SubscriptionId


################################
# Pause AnalysisServicesServers
################################
Write-Output "Checking Analysis Services Servers"

# Get list of all AnalysisServicesServers that are turned on (ProvisioningState = Succeeded)
# but skip AnalysisServicesServers that have an Environment tag with the value Production
$AnalysisServicesServers = Get-AzureRmAnalysisServicesServer | 
Where-Object {$_.ProvisioningState -eq "Succeeded" -and $_.Tag['Environment'] -ne "Production"}

# Loop through all AnalysisServicesServers to pause them
foreach ($AnalysisServicesServer in $AnalysisServicesServers)
{
    Write-Output "- Pausing Analysis Services Server $($AnalysisServicesServer.Name)"
    $null = Suspend-AzureRmAnalysisServicesServer -Name $AnalysisServicesServer.Name
}


################################
# Pause Virtual Machines
################################
Write-Output "Checking Virtual Machines"

# Get list of all Azure Virtual Machines that are not deallocated (PowerState <> VM deallocated)
# Filtering on tags is not supported for Azure Virtual Machines
$VirtualMachines = Get-AzureRmVM -Status |
Where-Object {$_.PowerState -ne "VM deallocated"} #-and $_.Tag['Environment'] -ne "Production"}

# Loop through all Virtual Machines to pause them
foreach ($VirtualMachine in $VirtualMachines)
{
    # Get-AzureRmVM does not show tags therefor
    # filtering in Where-Object does not work.
    # Workaround: if statement within loop
    if ($VirtualMachine.Tags['Environment'] -ne "Production")
    {
        Write-Output "- Deallocating Virtual Machine $($VirtualMachine.Name) "
        $null = Stop-AzureRmVM -ResourceGroupName $VirtualMachine.ResourceGroupName -Name $VirtualMachine.Name -Force 
    }
}
# Note: Classic Virtual machines are excluded with this script because they don't support Tags.
 

################################
# Pause SQL Data Warehouses
################################
Write-Output "Checking SQL Data Warehouses"

# Get list of all Azure SQL Servers
$SqlServers = Get-AzureRmSqlServer

# Loop through all SQL Servers to check if they host a DWH
foreach ($SqlServer in $SqlServers)
{
    # Get list of all SQL Data Warehouses (Edition=DataWarehouse) that are turned on (Status = Online)
    # but skip SQL Data Warehouses that have an Environment tag with the value Production
    $SqlDatabases = Get-AzureRmSqlDatabase -ServerName $SqlServer.ServerName -ResourceGroupName $SqlServer.ResourceGroupName |
    Where-Object {$_.Edition -eq 'DataWarehouse' -and $_.Status -eq 'Online' -and $_.Tag['Environment'] -ne "Production"} 

    # Loop through all SQL Data Warehouses to pause them
    foreach ($SqlDatabase in $SqlDatabases)
    {
        Write-Output "- Pausing SQL Data Warehouse $($SqlDatabase.DatabaseName)"
        $null = Suspend-AzureRmSqlDatabase -DatabaseName $SqlDatabase.DatabaseName -ServerName $SqlServer.ServerName -ResourceGroupName $SqlDatabase.ResourceGroupName
    }
}


Write-Output "Done"

Note 1: This is a very basic script. No error handling has been added. Check the AzureAutomationTutorialScript for an example. Finetune it for you own needs.
Note 2: There are often two versions of an method like Get-AzureRmSqlDatabase and Get-AzureSqlDatabase. Always use the one with "Rm" in it (Resource Managed), because that one is for the new Azure portal. Without Rm is for the old/classic Azure portal.
Note 3: Because Azure Automation doesn't support Out-Null I used an other trick with the $null =. However the Write-Outputs are for testing purposes only. Nobody sees them when they are scheduled.
Note 4: The code for Data Warehouses first loops through the SQL Servers and then through all databases on that server filtering on edition 'DataWarehouse'.
Note 5: The method to get Virtual Machines (Get-AzureRmVM) doesn't show tags. Therefor we cannot use the Where-Object filter to filter out certain tags. Workaround: if-statement within foreach loop.

7) Testing
You can use the Test Pane menu option in the editor to test your PowerShell scripts. When clicking on Run it will first Queue the script before Starting it. If nothing needs to be paused the script runs in about a minute, but pausing or deallocating items takes several minutes.
Testing the script in the Test Pane















8) Publish
When your script is ready, it is time to publish it. Above the editor click on the Publish button. Confirm overriding any previously published versions.
Publish the Runbook










9) Schedule
And now that we have a working and published Azure Runbook, we need to schedule it. Click on Schedule to create a new schedule for your runbook. For this pause everything script I created a schedule that runs every day on 2:00AM (02:00). This gives late working colleagues more than enough time to play with all the Azure stuff before there service will be paused.
Add Schedule















Summary
In this post you saw how you can pause all expensive services in an Azure playground environment. If a co-worker don't wants to pause his/her service then he/she can skip that by adding a tag to the specific server or service. As mentioned before: this is not a complete list. Feel free to suggest more services, that can be paused, in the comments.