Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ranstett
Regular Visitor

Custom Visual dataViewMappings Setting Up

I'm working on a project to generate a custom visual that is a matrix with 2 groups (x, y) and 2 measures. Bascially it's a heatmap were the color value is measure2 while the display value is measure1. I've been able to get it working using the basic Value Data Role. But when I tried swap it out for XAxis, YAxis, Measure1, and Measure2 data roles I can't get it to work. Below is the capabilities.json file but I can't figurout the how to setup the dataViewMappings. 

 

Here is an example of the data:

XAxis         YAxis         Measure1         Measure2          

Product1   State1       300                    105

Product2   State1       256                     75

Product1   State2       50                       15

 

 

{
  "dataRoles": [
    {
      "displayName": "Display Values",
      "kind": "Measure",
      "name": "measure1"
    },
    {
      "displayName": "Heat Values",
      "kind": "Measure",
      "name": "measure2"
    },
    {
      "displayName": "X Axis.",
      "kind": "Grouping",
      "name": "xAxis"
    },
    {
      "displayName": "Y Axis.",
      "kind": "Grouping",
      "name": "yAxis"
    }
  ],
  "dataViewMappings": [
    {
      "conditions": [
        {
          "measure1": {
            "max": 1
          },
          "measure2": {
            "max": 1
          },
          "xAxis": {
            "max": 1
          },
          "yAxis": {
            "max": 1
          }
        }
      ],
      "scriptResult": {
        "dataInput": {
          "table": {
            "rows": {
              "select": [
                { "for": { "in": "measure1" } },
                { "for": { "in": "measure2" } },
                { "for": { "in": "xAxis" } },
                { "for": { "in": "yAxis" } }
              ],
              "dataReductionAlgorithm": {
                "top": {}
              }
            }
          }
        },
        "script": {
          "scriptProviderDefault": "R",
          "scriptOutputType": "html",
          "source": {
            "objectName": "rcv_script",
            "propertyName": "source"
          },
          "provider": {
            "objectName": "rcv_script",
            "propertyName": "provider"
          }
        }
      }
    }
  ],
  "objects": {
    "rcv_script": {
      "properties": {
        "provider": {
          "type": {
            "text": true
          }
        },
        "source": {
          "type": {
            "scripting": {
              "source": true
            }
          }
        }
      }
    }
  },
  "suppressDefaultTitle": true
}

 

8 REPLIES 8
v-viig
Community Champion
Community Champion

@ranstett

 

Are you going to use it with R-script?

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Yes I'm using an R script and Plotly. One thing I failed to mention in my previous post is that I put a Stop(<dataRole>) in to see what values are being used. For the measures I get the correct values, but for the groups I'm getting numbers and not the actual text values. 

v-viig
Community Champion
Community Champion

As far as I know, Power BI might return numbers for grouping if the field contains numbers.

 

Does this fact affect your code somehow?

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Unfortunatly no because the data in those axis columns is text not numbers.

 

If I change the capabilties.json file back to it's original form:

 

 

{
  "dataRoles": [
    {
      "displayName": "Values",
      "kind": "GroupingOrMeasure",
      "name": "Values"
    }
  ],
  "dataViewMappings": [
    {
      "scriptResult": {
        "dataInput": {
          "table": {
            "rows": {
              "select": [
                { "for": { "in": "Values" } }
              ],
              "dataReductionAlgorithm": {
                "top": {}
              }
            }
          }
        },
        "script": {
          "scriptProviderDefault": "R",
          "scriptOutputType": "html",
          "source": {
            "objectName": "rcv_script",
            "propertyName": "source"
          },
          "provider": {
            "objectName": "rcv_script",
            "propertyName": "provider"
          }
        }
      }
    }
  ],
  "objects": {
    "rcv_script": {
      "properties": {
        "provider": {
          "type": {
            "text": true
          }
        },
        "source": {
          "type": {
            "scripting": {
              "source": true
            }
          }
        }
      }
    }
  },
  "suppressDefaultTitle": true
}

I can then access in my r script Values$[columnName], but the columnNames need to be hard coded. I'm basically trying to genericize this visual so I can use it with other data. 

 

 

Is there a way of seeing table definition? I tried to view it through dataViews[0] but that didn't seem to be available in R. Also is there a way to debug the R script with the data being sent it?

v-viig
Community Champion
Community Champion

Could you please send an email to pbicvsupport@microsoft.com? Or share your email?

We'd like to include our R-script engineer to assist you with this issue.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Anonymous
Not applicable

Was this ever resolved? I'm going through the same process, and I'm finding myself to be lost in the capabilities options for the different dataviewmappings.

 

Thanks!

ranstett
Regular Visitor

I'm working on a project to generate a custom visual that is a matrix with 2 groups (x, y) and 2 measures. Bascially it's a heatmap were the color value is measure2 while the display value is measure1. I've been able to get it working using the basic Value Data Role. But when I tried swap it out for XAxis, YAxis, Measure1, and Measure2 data roles I can't get it to work. Below is the capabilities.json file but I can't figurout the how to setup the dataViewMappings. 

 

Here is an example of the data:

XAxis         YAxis         Measure1         Measure2          

Product1   State1       300                    105

Product2   State1       256                     75

Product1   State2       50                       15

 

 

{
  "dataRoles": [
    {
      "displayName": "Display Values",
      "kind": "Measure",
      "name": "measure1"
    },
    {
      "displayName": "Heat Values",
      "kind": "Measure",
      "name": "measure2"
    },
    {
      "displayName": "X Axis.",
      "kind": "Grouping",
      "name": "xAxis"
    },
    {
      "displayName": "Y Axis.",
      "kind": "Grouping",
      "name": "yAxis"
    }
  ],
  "dataViewMappings": [
    {
      "conditions": [
        {
          "measure1": {
            "max": 1
          },
          "measure2": {
            "max": 1
          },
          "xAxis": {
            "max": 1
          },
          "yAxis": {
            "max": 1
          }
        }
      ],
      "scriptResult": {
        "dataInput": {
          "table": {
            "rows": {
              "select": [
                { "for": { "in": "measure1" } },
                { "for": { "in": "measure2" } },
                { "for": { "in": "xAxis" } },
                { "for": { "in": "yAxis" } }
              ],
              "dataReductionAlgorithm": {
                "top": {}
              }
            }
          }
        },
        "script": {
          "scriptProviderDefault": "R",
          "scriptOutputType": "html",
          "source": {
            "objectName": "rcv_script",
            "propertyName": "source"
          },
          "provider": {
            "objectName": "rcv_script",
            "propertyName": "provider"
          }
        }
      }
    }
  ],
  "objects": {
    "rcv_script": {
      "properties": {
        "provider": {
          "type": {
            "text": true
          }
        },
        "source": {
          "type": {
            "scripting": {
              "source": true
            }
          }
        }
      }
    }
  },
  "suppressDefaultTitle": true
}

 

v-viig
Community Champion
Community Champion

Looks like it's a duplicate of this one.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.