Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.32 KB | None | 0 0
  1. <div id="container"></div>
  2.  
  3. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  4. <script src="powerbi.min.js"></script>
  5.  
  6. <script>
  7.  
  8.     var container = document.getElementById("container");
  9.  
  10.     // -------------------------------------------------------------------------
  11.     // Power BI Authentication/Session:
  12.     // -------------------------------------------------------------------------
  13.     // Guide: https://docs.microsoft.com/en-us/power-bi/developer/walkthrough-push-data-get-token
  14.     // 1. You need to acquire an AccessToken on the backend (don't do this over JS)
  15.     // 2. You will need to find the report you want to display
  16.     // 3. You just need the accessToken, reportId, and embedUrl to embed
  17.     // -------------------------------------------------------------------------
  18.     var accessToken = "", // the active session; it will expire after several minutes
  19.         reportId = "", // the guid id connected to the Power BI file you uploaded
  20.         embedUrl = ""; // the embed URL for that report
  21.  
  22.     var report = powerbi.embed(container, {
  23.         type: "report",
  24.         accessToken: accessToken,
  25.         id: reportId,
  26.         embedUrl: embedUrl,
  27.         settings: {
  28.             filterPaneEnabled: false,
  29.             navContentPaneEnabled: false
  30.         }
  31.     });
  32.  
  33.     // Filter variables
  34.     var targetTable = "tblSomeData", // The target table in the Power BI report you want to filter against
  35.         targetColumn = "Title", // The column you want to filter on
  36.         targetValue = "Mr. Smith", // The value you want to search for
  37.         operatorCondition = "Contains"; // The operator condition you want to use for the search
  38.  
  39.     // Filter being done:
  40.     // 1. Search the "Title" column of the "tblSomeData" Table
  41.     // 2. Look for records containing "Mr. Smith"
  42.     report.setFilters([{
  43.                 $schema: "http://powerbi.com/product/schema#advanced",
  44.                 target: {
  45.                     table: targetTable,
  46.                     column: targetColumn
  47.                 },
  48.                 logicalOperator: "OR",
  49.                 conditions: [{ operator: operatorCondition, value: targetValue }]
  50.             }]).then(function (result) { console.log("Filtered!"); })
  51.                 .catch(function (er) { console.warn(er); });
  52.  
  53.  
  54. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement