cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
GuFa
Frequent Visitor

Add one datafield to multiple measures

I have a capabilities files with some measures in it.

 

 

  "dataRoles": [
    {
      "displayName": "Chart 1 X-Axis",
      "name": "chart1_X",
      "kind": "Measure"
    },
    {
      "displayName": "Chart 1 Y-Axis",
      "name": "chart1_Y",
      "kind": "Measure"
    },
    {
      "displayName": "Chart 2 X-Axis",
      "name": "chart2_X",
      "kind": "Measure"
    },
    {
      "displayName": "Chart 2 Y-Axis",
      "name": "chart2_Y",
      "kind": "Measure"
    },
...

 

 

and I want to ad one datafield to multiple measures. But power bi sees the measure only onece.

 

GuFa_0-1633104958182.png

 

I want to have at categories.values[2] params2 instead of TotalSegment. I read the Input via a loop and would like to have TotalSegment at categories.values[2].

 

Any hints help appreciated.

 

br

1 ACCEPTED SOLUTION
dm-p
Super User
Super User

Hi @GuFa,

It's great that you're thinking about this scenario from an end-user perspective and making sure that you have a path for it 🙂

From a data perspective, this is a limitation with Power BI that cannot be managed in this way: a column or measure can only be referenced once in an underlying query and as such cannot be mapped to the data view twice. You can't do much about it from withn the capabilities, as you want a user to be able to add a column in here; as such you will need to manage this internally when mapping your data from the data view into your viewmodel based on checking for conditions.

How you might approach this at a high-level is something like the following:

  • When mapping your data to your view model, check to see if you have anything in the chart2_X data role for the data view. You can use methods in the DataRoleHelper to assist with this.
  • If you do have a different column present, bind the values from the discovered column in your viewmodel; if not, bind the values from chart1_X's column/role.

You may find a better way based on your implementation, but this might give you some ideas to try.

Good luck,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

2 REPLIES 2
dm-p
Super User
Super User

Hi @GuFa,

It's great that you're thinking about this scenario from an end-user perspective and making sure that you have a path for it 🙂

From a data perspective, this is a limitation with Power BI that cannot be managed in this way: a column or measure can only be referenced once in an underlying query and as such cannot be mapped to the data view twice. You can't do much about it from withn the capabilities, as you want a user to be able to add a column in here; as such you will need to manage this internally when mapping your data from the data view into your viewmodel based on checking for conditions.

How you might approach this at a high-level is something like the following:

  • When mapping your data to your view model, check to see if you have anything in the chart2_X data role for the data view. You can use methods in the DataRoleHelper to assist with this.
  • If you do have a different column present, bind the values from the discovered column in your viewmodel; if not, bind the values from chart1_X's column/role.

You may find a better way based on your implementation, but this might give you some ideas to try.

Good luck,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

GuFa
Frequent Visitor

Hi Daniel,

 

Thank you very much for detailed explanation, it helped a lot :). At metadata I can see all the input datafields. I was able to grab and copy them into my data array. 

 

br

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.