Skip to content

Clone Visual

Amit Shuster edited this page Jan 24, 2021 · 6 revisions
ℹ️ This wiki has been deprecated
All our Client APIs documentation and references can be found in the new Power BI embedded analytics Client APIs documentation set.
For the content of this article see Clone a visual.

Use clone visual API to clone a specific visual into active page. It's helpful when you want to create copies of one visual with different filters or different layout.

API Definition

For a definition of IFilter please see Filters Wiki page. For a definition of IVisualLayout please see Custom layout Wiki page.

interface ICloneVisualRequest {
  // The filters which will be applied to the new visual. Default: source visual filters.
  filters?: IFilter[];

  // The layout which will be applied to the new visual.
  // Default: a best effort to put a new visual in an empty space on the canvas.
  layout?: IVisualLayout;

  // Focus on the new visual after creation.
  // If autoFocus is set to false, no scrolling will occur.
  // Default: true.
  autoFocus?: boolean;
}

interface ICloneVisualResponse {
  // New visual name
  visualName: string;
}

Visual object has a method called clone which is defined as:

clone(request: models.ICloneVisualRequest = {}): Promise<ICloneVisualResponse>

To get a list of visual on a report please see Get-Visuals Wiki.

Code Sample

Example 1

Clone a visual as is. The new position and size of the new visual will be a best effort to put a visual on an empty space on the canvas. If you want a specific position and size, please see second example.

    visual.clone()
        .then(function (result) {
            console.log(result.name);
        })
        .catch(function (errors) {
            console.log(errors);
        });

Example 2

Clone a visual with new layout without focusing on it.

    let cloneRequest = {
        layout: { x: 150, y: 250 },
        autoFocus: false
    };

    visual.clone(cloneRequest)
        .then(function (result) {
            console.log(result.name);
        })
        .catch(function (errors) {
            console.log(errors);
        });

Example 3

Clone a visual with new layout and a new list of visual level filters.

    const basicFilter: pbi.models.IBasicFilter = {
      $schema: "http://powerbi.com/product/schema#basic",
      target: {
        table: "Store",
        column: "Count"
      },
      operator: "In",
      values: [1,2,3,4],
      filterType: pbi.models.FilterType.BasicFilter
    };

    let cloneRequest = {
        layout: { x: 150, y: 250 },
        filters: [basicFilter]
    };

    visual.clone(cloneRequest)
        .then(function (result) {
            console.log(result.name);
        })
        .catch(function (errors) {
            console.log(errors);
        });

Limitations and considerations

  • You can clone a visual only if the report is fully rendered. That means you need to wait on 'rendered' event before calling clone visual API.

  • You can clone a visual from any page in the report to the active page.

Clone this wiki locally