Tag: powerbi

  • Creating SVG Powered Navigation Buttons in PowerBI

    Creating SVG Powered Navigation Buttons in PowerBI

    Not every SVG needs to be used as a measure in Power BI. In some cases, it makes more sense to take a simpler approach and use .SVG files directly. This is especially helpful when working with buttons in Power BI, which currently do not support imageURL (like we would use in the new card visuals, for example) and instead only allow image input. Hopefully this blog post helps you with creating SVG powered navigation buttons in PowerBI.

    Thankfully, those image options give us all we need to make buttons more dynamic. You can use animated SVG icons or even animate the entire button if needed.

    Power BI buttons let you define multiple visual states, including Default, Hover, Selected etc. Each state can be customised with different settings for Text, Icon, Fill, and Border. Both Icon and Fill accept image files.

    SVG files can contain coded information, which means you can embed animation directly into them. You just need to make sure the .SVG file is correctly structured and works as expected inside Power BI.

    A useful tool for testing and previewing SVG files is https://www.svgviewer.dev.

    This example uses the Icon section of the button visual. Here, we apply an animated SVG that responds to the button state, such as when a user hovers over it.

    For this example, I am creating a simple arrow that moves up and down when the button is hovered over. We need two versions of the SVG. One will be static for the default state. The other will contain the animation for the hover state.

    Note: Make sure to include the namespace in your SVG. This is required for it to render correctly in Power BI.

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <svg 
       xmlns="http://www.w3.org/2000/svg"
    width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="1" stroke-linecap="round" stroke-linejoin="round">
      <line x1="6" y1="18" x2="18" y2="6" />
      <polyline points="10 6 18 6 18 14" />
    </svg>
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <svg 
       xmlns="http://www.w3.org/2000/svg"
    width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="1" stroke-linecap="round" stroke-linejoin="round">
      <g>
        <animateTransform
          attributeName="transform"
          type="translate"
          values="0 0; 1 -1; 2 -2; 3 -3; 4 -4; 0 0"
          keyTimes="0; 0.1; 0.25; 0.45; 0.8; 1"
          dur="2s"
          repeatCount="indefinite"
        />
        <line x1="6" y1="18" x2="18" y2="6" />
        <polyline points="10 6 18 6 18 14" />
      </g>
    </svg>

    Copy the code up to https://www.svgviewer.dev/ to preview, from here you can also download the .svg file as well which makes things nice and simple!

    Into PowerBI, Insert a new blank button, select the button to format at and under Style / Icon, choose Icon Type – Custom

    Next we need to apply the two image files, one for the default status and the other for hover

    Default

    • Under Style Apply Settings to: Firstly make the state as Default
    • Next, go back to the Icon section and apply the static SVG. I set the image fit as normal
    • Tweak the placement as required using alignment and padding ( I used left horizontal alignment, middle vertical, with padding of 10 on the left and 7 at the bottom.
    • I then set the icon size at 40, but against this can be tweaked as required

    Hover

    • This time under Style Apply Settings to: Switch to Hover
    • Back Under Icon, apply the animated svg. And set the image fit the same as your default setting (especially if using a similar icon for each)
    • If using the same icon like I have in this example ensure your placement and size matches the default settings
    • In my example I also added an extra border around the button, feel free to experiment and see what you like best!

    This example instead uses the Fill option of the button visual. Again, we apply an animated SVG that responds to the button state, such as when a user hovers over it but this time instead of affecting an icon, we can affect the button itself.

    For this example, a wave animation down the left hand side of the button that appears once hovered over. Unlike the icon example, we only need one SVG file this time as our default state for this example is just a solid fill background (just make sure your background matches the colour we are adding for the svg)

    Note: Make sure to include the namespace in your SVG. This is required for it to render correctly in Power BI.

    <svg xmlns="http://www.w3.org/2000/svg" width="259" height="74" viewBox="0 0 259 74">
      <style>
        .wave-accent {
          fill: #6bfad8;
          animation: waveMove 4s linear infinite;
        }
    
        @keyframes waveMove {
          0% { transform: translateY(0); }
          100% { transform: translateY(-160px); }
        }
      </style>
      <rect x="0" y="0" width="259" height="74" rx="6" ry="6" fill="#292929" />
      <defs>
        <clipPath id="waveClip">
          <rect x="0" y="0" width="25" height="74" />
        </clipPath>
      </defs>
      <g clip-path="url(#waveClip)">
        <g class="wave-accent">
          <path d="M12.5,0 q10,10 0,20 -10,10 0,20 10,10 0,20 -10,10 0,20 10,10 0,20 -10,10 0,20 10,10 0,20 -10,10 0,20 H0 V0 Z" />
          <path d="M12.5,160 q10,10 0,20 -10,10 0,20 10,10 0,20 -10,10 0,20 10,10 0,20 -10,10 0,20 10,10 0,20 -10,10 0,20 H0 V160 Z" />
        </g>
      </g>
    </svg>
    

    Copy the code up to https://www.svgviewer.dev/ to preview and download the .SVG file.

    Note this time, we have added the width and height in various parts of the code. This needs to match up with your size of the button in PowerBI to ensure if fills the whole area

    Into PowerBI, Insert a new blank button, select the button to format at and under Style / Icon, choose Icon Type – Custom

    Next we need to apply the single image file for the hover status

    Default

    • Under Style Apply Settings to: Ensure we are set on Default
    • Ensure the fill colour is set to exactly the same colour being used within your button
    • You may want to tweak the positioning of the text on your button, I applied middle horizontal and vertical alignment and then moved it around with padding

    Hover

    • Under Style Apply Settings to: Switch to Hover
    • Under Fill, browse and apply the animated svg. In this instance I’ve set the Image Fit just as Normal

    And that now should be it! You should have two different types of animated navigation buttons, you can apply the actions you need them to do down in the button settings and you are sorted!

    Please play around experiment with different types and shapes and of course share!

    Thanks for reading!

  • Updating PowerBI reports with Powershell Version 2

    Updating PowerBI reports with Powershell Version 2

    After a recent update for Prism, I needed to make some changes to my PowerBI update script. This is updating PowerBI reports with Powershell version 2!

    My Powershell scripts have served me well for some time, but after a couple of errors popped up, I found a few extra ways to make it more efficient and also improve how it was handling parameters!

    One thing I noticed was that parameters occasionally failed to load correctly after a PBIX upload. This was due to the upload automatically triggering a dataset refresh, which temporarily blocked the API from accepting new parameter values.

    Turns out this was due to having scheduled refreshes enabled on the existing dataset. The solution, temporarily disable the scheduled refresh!

    So if you have the requirement where you have multiple instances of the same report across the same or different workspaces and need to update them with your latest pbix file this script is for you!

    What the script does?

    This script will pick up a pbix file then scan over your workspaces (based on when filters you apply). When it finds reports that again match your criteria, it will take a copy of the current parameters, temporarily disable the scheduled refresh, update the pbix file and then load the parameters back in. When its finished, it will reenable the scheduled refresh. In some cases I’ve then set it to perform a refresh straight after to load the data back into the report.

    So this means you can upload to the PowerBI service with your pbix file from a single source file, the parameters all remain the same as before, and then we pull in the data based on those parameters and all good to go!

    As part of version control, I currently use a parameter to record the current version of my reports. This adds an extra benefit, as I can then use this script to check if the reports are already on the expected version. Just in case the script is interrupted, or we need to deploy in stages.

    I then add in the new version number as part of the script and this becomes a great way to track report versions when updating PowerBI reports with PowerShell.

    How it works?

    • Connects to Power BI Service using Connect-PowerBIServiceAccount.
    • Retrieves all Power BI workspaces using Get-PowerBIWorkspace.
    • Loops through each workspace and identifies reports whose names start with “AETHER”. (or however best for you)
    • For each report:
    • Retrieves the dataset parameters.
    • Updates the first parameter’s value to a specified version if it doesn’t already match.
    • Disables scheduled refresh
    • Overwrites the report in the workspace using a specified PBIX file ($FilePath).
    • Takes over the dataset to ensure permissions are set correctly.
    • Updates the dataset parameters.
    • Re-enables the scheduled refresh

    Key things you can change

    • $DeployVer: The new deployment version to update the first parameter to (e.g., “2025Q2”).
    • The reports to find matching a name convention e.g. $_.Name -LIKE ‘*AETHER*’
    • $FilePath: The path to the PBIX file used for updating reports.
    • Parameter 0 is assumed to represent a version parameter (e.g., “2025Q2”)
    # Connect to Power BI Service Account
    Connect-PowerBIServiceAccount
    
    # Set the deployment version to be used for updating parameters
    $DeployVer = "2025Q2"
    
    # Define the path to the PBIX file to be used for report updates
    $FilePath = "C:\MYFILEPATH\REPORT.pbix"
    
    # Define the conflict action for updating reports (e.g., Create or Overwrite existing reports)
    $Conflict = "CreateOrOverwrite"
    
    # Retrieve all Power BI workspaces
    $workspaces = Get-PowerBIWorkspace -all
    
    # Loop through each workspace
    foreach ($workspace in $workspaces) {
    
        # Get all reports in the current workspace with names starting with "AETHER" - adjust the filter as needed
        $Reportlist = Get-PowerBIReport -WorkspaceId $workspace.Id | Where-Object -FilterScript {
            $_.Name -LIKE '*AETHER*'
        }
    
        # Check if any reports were found in the workspace
        if ($Reportlist) {
            Write-Host "Workspace: $($workspace.Name)" # Log the workspace name
    
            # Loop through each report in the report list
            foreach ($Report in $Reportlist) {
                Write-Host "  Report: $($Report.Name)" # Log the report name
    
                try {
                    # Retrieve the parameters of the dataset associated with the report
                    $ParametersJsonString = Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($Report.DatasetId)/parameters" -Method Get
                    $Parameters = (ConvertFrom-Json $ParametersJsonString).value # Convert JSON response to PowerShell object
                } catch {
                    Write-Host "Error retrieving parameters: $($_.Exception.Message)"
                    continue
                }
    
                $JsonBase = @{}
                $JsonString = $null # Initialize JSON string variable
    
                # Initialize an empty array to hold parameter updates
                $UpdateParameterList = New-Object System.Collections.ArrayList
    
                # Loop through each parameter and prepare the update list
                foreach ($Parameter in $Parameters) {
                    $UpdateParameterList.add(@{"name" = $Parameter.name; "newValue" = $Parameter.currentValue})
                }
    
                # Check if there are any parameters to update
                if ($UpdateParameterList.Count -gt 0) {
                    # Get the current value of the Version parameter
                    $currentparam = $UpdateParameterList[0].newValue
    
                    Write-Host "Current Parameter Version Value: $currentparam" # Log the current parameter value
    
                    # Check if the current parameter value matches the deployment version
                    if ($currentparam -ne $DeployVer) {
                        Write-Host "Version does not match. Updating..." # Log the update action
    
                        # Display current parameters
                        $UpdateParameterList.newValue
    
                        # Update the first parameter to the new deployment version
                        $UpdateParameterList[0].newValue = $DeployVer
    
                        # Prepare the JSON payload for updating parameters
                        $JsonBase.Add("updateDetails", $UpdateParameterList)
                        $JsonString = $JsonBase | ConvertTo-Json
    
                        # Define the report name
                        $ReportName = $Report.Name
    
                        # Disable refresh schedule for the dataset
                        $disableRefreshBody = @"
    {
    "value": {"enabled": false}
    }
    "@
    
                        try {
                            Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($Report.DatasetId)/refreshSchedule" -Method Patch -Body ("$disableRefreshBody")
                            Write-Host "Refresh schedule disabled for dataset: $($Report.DatasetId)"
                        } catch {
                            Write-Host "Failed to disable refresh schedule: $($_.Exception.Message)"
                        }
    
                        try {
                            # Take over the dataset to ensure permissions are set correctly
                            Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($Report.DatasetId)/Default.TakeOver" -Method Post
                        } catch {
                            Write-Host "Error taking over dataset: $($_.Exception.Message)"
                            continue
                        }
    
                        try {
                            # Update the existing report in the workspace
                            New-PowerBIReport -Path $FilePath -Name $ReportName -WorkspaceId $workspace.Id -ConflictAction $Conflict
                        } catch {
                            Write-Host "Error uploading report: $($_.Exception.Message)"
                            continue
                        }
    
                        try {
                            # Update the parameters of the dataset
                            Start-Sleep 5
                            Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($Report.DatasetId)/Default.UpdateParameters" -Method Post -Body $JsonString
                        } catch {
                            Write-Host "Error updating parameters: $($_.Exception.Message)"
                            continue
                        }
    
                        # Reenable refresh schedule for the dataset
                        $enableRefreshBody = @"
    {
    "value": {"enabled": true}
    }
    "@
    
                        try {
                            Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($Report.DatasetId)/refreshSchedule" -Method Patch -Body ("$enableRefreshBody")
                            Write-Host "Refresh schedule Enabled for dataset: $($Report.DatasetId)"
                        } catch {
                            Write-Host "Failed to Enable refresh schedule: $($_.Exception.Message)"
                        }
    
                        Remove-Variable UpdateParameterList, JsonString -ErrorAction SilentlyContinue
                    } else {
                        Write-Host "Version already matches. Skipping update." # Log if no update is needed
                    }
                } else {
                    Write-Host "No parameters found for this dataset." # Log if no parameters are found
                }
            }
        } else {
            Write-Host "No reports found in workspace: $($workspace.Name)" # Log if no reports are found in the workspace
        }
    }
    
    # Log the completion of the script
    Write-Host "Script completed."

    This approach has saved me hours on PBIX deployment.
    If you discover any useful additions or tweaks, feel free to reach out on LinkedIn or by email I’d love to hear how you’ve adapted it.

    Thanks for reading!

    https://github.com/AetherAdv/powerbi_powershell_updatereports

  • Dynamic PowerBI Backgrounds

    Dynamic PowerBI Backgrounds

    If you saw a couple of my posts on LinkedIn you would have seen some of the things I have been doing to mess with SVGs, HTML, animation and in this initial case Pokémon. I wanted to build a way to be able to seamlessly transition from one colour background to another but in a smooth and animated way driven by slicers, and all linked to dax measures. So, this blog post will give you a quick and easy way to achieve Dynamic PowerBI Backgrounds,

    Doing things this way means rather than relying on bookmarks, theme files to switch up colours or implement ideas such as dark mode we can instead add smooth transitions and make changes in a more dynamic way.

    Use SVG, HTML & CSS to enhance PowerBI reports – Home

    Firstly I configured the measure – this is currently linked to a simple table referencing the Background Type but this of course could be any of your values / data sets.

    I have created two sets of colours relating to the selected option to show the two ends of the gradient. This means when we apply the animation we gain a subtle effect (of course you could just use a simple base colour).

    To create a smoother transition between colours I have set all to initially show as a warm white colour, so instead of instantly performing a jarring switch, the screen goes light and slowly moves to the new selected colour. In my code I have also layered a slight vignette to the edges of the image to emphasise the display.

    As part of this code it is also important to select the correct width and height to ensure the effect fills the screen (set the same as your PBI reports or at least the same aspect ratio such as 1920×1080 if using 16:9)

    HTML_Dynamic_Back = 
    VAR selectedOption =
        // Get the selected background option, defaulting to "Light" if none is selected
        SELECTEDVALUE(BackgroundType[BackgroundType], "Light")
    
    VAR gradientStart =
        // Define gradient start colours for each option
        SWITCH(
            TRUE(),
            selectedOption = "Light", "#F2EFE9",  
            selectedOption = "Dark", "#1A1A1A",   
            selectedOption = "Middle", "#A8A8A8", 
            selectedOption = "Red", "#F08030",   
            selectedOption = "Green", "#78C850",  
            selectedOption = "Blue", "#6890F0",   
            selectedOption = "Yellow", "#F8D030", 
            selectedOption = "Orange", "#FFA500", 
            "#6BFAD8"                             
        )
    
    VAR gradientEnd =
        // Define gradient end colours for a lighter variation of each option
        SWITCH(
            TRUE(),
            selectedOption = "Light", "#FFFFFF",  
            selectedOption = "Dark", "#575757",   
            selectedOption = "Middle", "#D8D8D8", 
            selectedOption = "Red", "#FFD6C1",    
            selectedOption = "Green", "#E6FFE6",  
            selectedOption = "Blue", "#E6F5FF", 
            selectedOption = "Yellow", "#FFFFE0", 
            selectedOption = "Orange", "#FFE6CC", 
            "#FFFFFF"                             
        )
    
    VAR warmOffWhite = "#F2EFE9" // A warm off-white base colour
    
    VAR svg =
        // Construct the SVG with animated gradients and vignette effect
        "<svg xmlns='http://www.w3.org/2000/svg' width='1920' height='1080' preserveAspectRatio='none'>" &
        "   <defs>" &
        "       <linearGradient id='bg-gradient' x1='0%' y1='0%' x2='100%' y2='100%'>" &
        "           <stop offset='0%' stop-color='" & warmOffWhite & "'>" &
        "               <animate attributeName='stop-color' values='" & warmOffWhite & ";" & gradientStart & "' dur='4s' begin='0s' fill='freeze' repeatCount='1'/>" &
        "               <animate attributeName='stop-color' values='" & gradientStart & ";" & gradientEnd & ";" & gradientStart & "' dur='6s' begin='4s' repeatCount='indefinite'/>" &
        "           </stop>" &
        "           <stop offset='100%' stop-color='" & warmOffWhite & "'>" &
        "               <animate attributeName='stop-color' values='" & warmOffWhite & ";" & gradientEnd & "' dur='4s' begin='0s' fill='freeze' repeatCount='1'/>" &
        "               <animate attributeName='stop-color' values='" & gradientEnd & ";" & gradientStart & ";" & gradientEnd & "' dur='6s' begin='4s' repeatCount='indefinite'/>" &
        "           </stop>" &
        "           <animate attributeName='x1' values='0%; -20%; 0%; 20%; 0%' dur='15s' repeatCount='indefinite'/>" &
        "           <animate attributeName='y1' values='0%; -20%; 0%; 20%; 0%' dur='15s' repeatCount='indefinite'/>" &
        "           <animate attributeName='x2' values='100%; 120%; 100%; 80%; 100%' dur='15s' repeatCount='indefinite'/>" &
        "           <animate attributeName='y2' values='100%; 120%; 100%; 80%; 100%' dur='15s' repeatCount='indefinite'/>" &
        "       </linearGradient>" &
        "       <radialGradient id='vignette-gradient' cx='50%' cy='50%' r='75%' fx='50%' fy='50%'>" &
        "           <stop offset='0%' stop-color='black' stop-opacity='0'/>" &
        "           <stop offset='60%' stop-color='black' stop-opacity='0'/>" &
        "           <stop offset='80%' stop-color='#575757' stop-opacity='0.02'/>" &
        "           <stop offset='100%' stop-color='#575757' stop-opacity='0.1'/>" &
        "       </radialGradient>" &
        "   </defs>" &
        "   <rect width='1920' height='1080' fill='url(#bg-gradient)'/>" &
        "   <rect width='1920' height='1080' fill='url(#vignette-gradient)'/>" &
        "</svg>"
    
    RETURN
        "data:image/svg+xml;utf8," & svg

    In this step we need to setup the card to be able to apply the measure. As with my other examples I have been using the new card visual.

    Firstly, on the card, apply the measure under the image section.

    • Select Image URL
    • Select the measure
    • Add a column / value to the card to the Data parameter (any is fine we are going to remove this from view)

    Next we need to resize the card to the full size of the window (or at least the area wanting to use) and then disable the values / labels under the Callout values section:

    • Disable Values
    • Disable Label

    Now all padding needs to be removed from the card as well as removing all existing backgrounds / style effects

    Under Visual / Cards:

    • Disable Background
    • Disable Border
    • Change Padding to custom and set all to 0px

    Under Visual / Images

    • Change Space between Image and callout to 0px

    Under General / Effects

    • Disable Background
    • Under General / Properties
    • Set all Padding to 0px

    Now to test – I’ve added a slicer to switch between the different colours in my measure for example

    To get the best effect from the dynamic background I have set a level of transparency to the visuals (if not dynamically changing these colours too)

    Thanks for reading! Please have a play and let me know what cool things you make! Some actual use cases so far: enhancing UI / UX, a way to light mode / dark mode or accessibility options!