### Installation Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/developer/visuals/utils-test.md Install the test utils package and add it as a dependency to your project's package.json file. ```APIDOC ## Installation To install test utils and add its dependency to your *package.json*, run the following command from your Power BI visuals directory: ```bash npm install powerbi-visuals-utils-testutils --save ``` ``` -------------------------------- ### Install dependencies via command line Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/developer/visuals/unit-tests-introduction.md Command to install all packages defined in the package.json file. ```cmd npm install ``` -------------------------------- ### ChartUtils Installation Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/developer/visuals/utils-chart.md Instructions on how to install the powerbi-visuals-utils-chartutils package. ```APIDOC ## Installation To install the package, you should run the following command in the directory with your current visual: ```bash npm install powerbi-visuals-utils-chartutils --save ``` ``` -------------------------------- ### Installation Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/developer/visuals/utils-type.md Install the powerbi-visuals-utils-typeutils package using npm. ```APIDOC ## Installation To install the package, run the following command in the directory with your current custom visual: `npm install powerbi-visuals-utils-typeutils --save` This command installs the package and adds a package as a dependency to your `package.json` file. ``` -------------------------------- ### Install R Packages for Power BI Visuals using R Console Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/create-reports/desktop-r-powered-custom-visuals.md This snippet demonstrates how to install necessary R packages for a Power BI custom visual by sourcing a provided R script from an R console. It includes example paths for different R installations. ```console source("C:/Users/david/Downloads/ScriptInstallPackagesForForecastWithWorkarounds.R") ``` ```text Typical default installation locations are the following: c:\Program Files\R\R-3.3.x\bin\x64\Rterm.exe (for CRAN-R) c:\Program Files\R\R-3.3.x\bin\x64\Rgui.exe (for CRAN-R) c:\Program Files\R\R-3.3.x\bin\R.exe (for CRAN-R) c:\Program Files\Microsoft\MRO-3.3.x\bin\R.exe (for MRO) c:\Program Files\Microsoft\MRO-3.3.x\bin\x64\Rgui.exe (for MRO) c:\Program Files\RStudio\bin\rstudio.exe (for RStudio) ``` -------------------------------- ### Clone and build the sample service Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/developer/execute-dax-queries-arrow/dotnet-mid-tier-service.md Clone the sample repository and verify that the solution compiles successfully before making modifications. ```bash git clone https://github.com/dbrownems/Microsoft.Samples.XMLA.ExecuteQueries.git cd Microsoft.Samples.XMLA.ExecuteQueries dotnet build ``` -------------------------------- ### Install Power BI Authoring Plugin Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/developer/agentic/power-bi-agentic-overview.md Add the skills-for-fabric marketplace and install the powerbi-authoring plugin using GitHub Copilot CLI. ```bash copilot plugin marketplace add microsoft/skills-for-fabric copilot plugin install powerbi-authoring@fabric-collection ``` -------------------------------- ### Calculate Start of Current Year Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/paginated-reports/expressions/report-builder-expression-examples.md Uses CDate, Now, and DateDiff functions to calculate the date representing the start of the current year. CDate converts strings to dates, Now gets the current date and time, and DateDiff calculates the difference between dates. ```Power BI Expressions =DateAdd(DateInterval.Year,DateDiff(DateInterval.Year,CDate("01/01/1900"),Now()),CDate("01/01/1900")) ``` -------------------------------- ### Get report URL for pageName Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/collaborate-share/service-embed-secure.md This is an example of a report URL from the Power BI service. The page name is typically found at the end of the URL. ```http https://app.powerbi.com/groups/me/reports/aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb/ReportSection2 ``` -------------------------------- ### GET /admin/activity-logs Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/guidance/admin-activity-log.md Retrieves activity logs for Power BI operations. This endpoint returns a list of activities performed by users, such as creating, updating, or installing apps. ```APIDOC ## GET /admin/activity-logs ### Description Retrieves a list of user activities within the Power BI environment, including app-related events like CreateApp, UpdateApp, and InstallApp. ### Method GET ### Endpoint /admin/activity-logs ### Parameters #### Query Parameters - **workspaceId** (string) - Optional - Filter activities by a specific workspace ID. - **date** (string) - Optional - Filter activities for a specific date. ### Request Example GET /admin/activity-logs?workspaceId=9325a31d-067e-4748-a592-626d832c8001 ### Response #### Success Response (200) - **Id** (string) - Unique identifier for the activity record. - **Operation** (string) - The type of operation performed (e.g., CreateApp, UpdateApp). - **UserId** (string) - The email address of the user who performed the action. - **CreationTime** (string) - The timestamp when the activity occurred. - **OrgAppPermission** (object) - Details regarding modified permissions if applicable. #### Response Example [ { "Id": "65a26480-981a-4905-b3aa-cbb3df11c7c2", "Operation": "CreateApp", "UserId": "jordan@contoso.com", "CreationTime": "2023-03-15T18:42:13Z", "ItemName": "Sales Reconciliations App", "IsSuccess": true } ] ``` -------------------------------- ### Implementing Selection Manager and Context Menu Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/developer/visuals/drill-down-support.md This documentation explains how to initialize the selection manager via the IVisualHost and trigger context menus on visual elements. ```APIDOC ## Power BI Visuals API: Selection Management ### Description This implementation allows custom visuals to handle user interactions such as clicks for data selection and right-click events to trigger the standard Power BI context menu. ### Method N/A (Visuals API Implementation) ### Endpoint IVisualHost.createSelectionManager() ### Parameters #### Path Parameters - **selectionID** (ISelectionId) - Required - The unique identifier for the data point being interacted with. ### Request Example // Initializing in constructor this.host = options.host; this.selectionManager = this.host.createSelectionManager(); ### Response #### Success Response (200) - **selectionManager** (ISelectionManager) - Returns an instance of the selection manager to handle selection and context menu events. #### Response Example // Triggering context menu this.selectionManager.showContextMenu(selectionID, { x: event.clientX, y: event.clientY }); ``` -------------------------------- ### Configure Windows or Basic Credentials (.NET SDK v3) Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/developer/embedded/configure-credentials.md Sets up Windows or Basic authentication credentials for a data source. Requires an AsymmetricKeyEncryptor for secure credential handling. ```csharp // Windows credentials var credentials = new WindowsCredentials(username: "john", password: "*****"); // Or // Basic credentials var credentials = new BasicCredentials(username: "john", password: "*****"); var credentialsEncryptor = new AsymmetricKeyEncryptor(publicKey); var credentialDetails = new CredentialDetails(credentials, PrivacyLevel.Private, EncryptedConnection.Encrypted, credentialsEncryptor); ``` -------------------------------- ### Power BI Report Server M Query Example Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/report-server/connect-data-source-apis.md This M query snippet demonstrates a basic SQL Server connection to a specified server and database. It's used as a starting point before parameterizing the connection details. ```M let Source = Sql.Database("localhost", "ReportServer"), dbo_ExecutionLog3 = Source{[Schema="dbo",Item="ExecutionLog3"]}[Data] in dbo_ExecutionLog3 ``` -------------------------------- ### Extract Date Parts with DatePart and DateInterval Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/paginated-reports/expressions/report-builder-expression-examples.md The DatePart function, used with DateInterval parameters, extracts specific components (like second, minute, hour, day, month, year) from a date. This example shows how to get the week number of the year. ```Power BI Expressions =DatePart(DateInterval.WeekOfYear, today()) ``` -------------------------------- ### Install C# dependencies Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/developer/execute-dax-queries-arrow/get-started.md Add the required .NET packages for Microsoft Authentication Library and Apache Arrow. ```bash dotnet add package Microsoft.Identity.Client dotnet add package Apache.Arrow ``` -------------------------------- ### Example API Call with Authorization Header Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/developer/embedded/troubleshoot-rest-api.md This snippet shows a typical GET request to a Power BI API endpoint, including the necessary Authorization header with a Bearer token. It also illustrates a common 403 Forbidden response with a TokenExpired error message. ```HTTP GET https://wabi-us-north-central-redirect.analysis.windows.net/metadata/cluster HTTP/1.1 Host: wabi-us-north-central-redirect.analysis.windows.net ... Authorization: Bearer eyJ0eXAiOi... ... HTTP/1.1 403 Forbidden ... {"error":{"code":"TokenExpired","message":"Access token has expired, resubmit with a new access token"}} ``` -------------------------------- ### Insert Sample Project Data Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/create-reports/translytical-task-flow-tutorial-status-update.md SQL script to insert sample data into the 'Project' table. This data is used for the tutorial. ```sql INSERT INTO [Project] ([Project id], [Project name], [Product name], [Description], [Priority], [Start date], [Target end date], [Budget], [Project manager], [Department], [Created date], [Created by], [Is active]) VALUES (1, 'Best Practices with Power BI - FabCon Atlanta', 'FabCon Atlanta', 'Session covering Power BI best practices for enterprise deployments', 'High', '2026-01-15', '2026-03-20', 5000.00, 'person1@somecompany.com', 'Developer Relations', '2026-01-15', 'Admin', 1), (2, 'Translytical Task Flows - Build', 'Microsoft Build', 'Deep dive into translytical workloads and real-time analytics patterns', 'Critical', '2026-02-01', '2026-05-19', 7500.00, 'person2@somecompany.com', 'Product Engineering', '2026-02-01', 'Admin', 1), (3, 'Advanced DAX Patterns - FabCon Barcelona', 'FabCon Barcelona', 'Workshop on complex DAX calculations and optimization techniques', 'High', '2026-03-01', '2026-09-15', 6000.00, 'person1@somecompany.com', 'Developer Relations', '2026-02-20', 'Admin', 1), (4, 'Semantic Modeling Deep Dive - Ignite', 'Microsoft Ignite', 'Comprehensive session on semantic model design and best practices', 'High', '2026-01-10', '2026-11-18', 8000.00, 'person2@somecompany.com', 'Product Engineering', '2026-01-10', 'Admin', 1), (5, 'Custom Visuals in Power BI - FabCon Atlanta', 'FabCon Atlanta', 'Hands-on lab for building custom visuals with the Power BI SDK', 'Medium', '2025-12-01', '2026-03-20', 4500.00, 'person1@somecompany.com', 'Developer Relations', '2025-12-01', 'Admin', 1), (6, 'TMDL for Version Control - Build', 'Microsoft Build', 'Session on using TMDL for semantic model source control and CI/CD', 'Critical', '2025-11-15', '2026-02-15', 5500.00, 'person2@somecompany.com', 'Product Engineering', '2025-11-15', 'Admin', 1), (7, 'Real-time Analytics with Power BI - Ignite', 'Microsoft Ignite', 'Showcase of Direct Lake and real-time streaming capabilities', 'High', '2026-02-10', '2026-11-18', 7000.00, 'person1@somecompany.com', 'Developer Relations', '2026-02-10', 'Admin', 1), (8, 'Semantic Modeling Workshop - FabCon Barcelona', 'FabCon Barcelona', 'Interactive workshop on building enterprise-grade semantic models', 'High', '2026-04-01', '2026-09-15', 6500.00, 'person2@somecompany.com', 'Product Engineering', '2026-02-25', 'Admin', 1); ``` -------------------------------- ### Get and Grant Permissions using HTTP Source: https://github.com/microsoftdocs/powerbi-docs/blob/main/powerbi-docs/developer/embedded/change-permissions.md This snippet demonstrates how to retrieve service principals and grant Power BI permissions to an application using HTTP requests to the Microsoft Graph API. It includes examples for creating service principals and granting OAuth2 permissions. ```HTTP Post https://graph.microsoft.com/v1.0/servicePrincipals HTTP/1.1 Authorization: Bearer ey..qw Content-Type: application/json { "accountEnabled" : true, "appId" : "{App_Client_ID}", "displayName" : "{App_DisplayName}" } ``` ```HTTP Post https://graph.microsoft.com/v1.0/OAuth2PermissionGrants HTTP/1.1 Authorization: Bearer ey..qw Content-Type: application/json { "clientId":"{Service_Plan_ID}", "consentType":"AllPrincipals", "resourceId":"a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1", "scope":"Dataset.ReadWrite.All Dashboard.Read.All Report.Read.All Group.Read Group.Read.All Content.Create Metadata.View_Any Dataset.Read.All Data.Alter_Any", "expiryTime":"2018-03-29T14:35:32.4943409+03:00", "startTime":"2017-03-29T14:35:32.4933413+03:00" } ``` ```HTTP Post https://graph.microsoft.com/v1.0/OAuth2PermissionGrants HTTP/1.1 Authorization: Bearer ey..qw Content-Type: application/json { "clientId":"{Service_Plan_ID}", "consentType":"AllPrincipals", "resourceId":"a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1", "scope":"User.Read Directory.AccessAsUser.All", "expiryTime":"2018-03-29T14:35:32.4943409+03:00", "startTime":"2017-03-29T14:35:32.4933413+03:00" } ```