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
Anonymous
Not applicable

Obtaining the unit information of the measures

Hello everyone, 

 

Basically need to get the unit information for a measure, I have been checking the "dataView " but havent seen any correspondent data.

 

Any help is welcome ! 

 

thanks for the support.

1 ACCEPTED SOLUTION
dm-p
Super User
Super User

Hi @Anonymous,

I'm still not 100% clear on your objectives here. How are you providing the unit information to your dataView? Is this what the dimensions data role represents in your dataViewMapping or is it a custom format string against the measure supplied as the  measures data role?

If you're setting a custom format string in the data model (e.g. "0.00 kg"), then it will come into the values array in the dataViewMapping as a raw value and its corresponding columns entry should have a format property that will contain the format string you've set up in the model.

You can then use valueFormatter from powerbi-visuals-utils-formattingutils to format the raw value using the format string from the object metadata. As there's no format property in for the measure metadata in your screenshot I'm guessing that isn't the case though.

Or, are you trying to introduce some logic into your visual to apply a denominator and add units to a measure based on a property?

What would be useful is if we could start with the following information:

  • dataRoles configuration (from capabilities.json)
  • Sample data you're adding to the visual, including any specifics around measure formatting and/or data types where applicable
  • Your dataViewMapping doesn't have any conditions on it, so confirmation on how many fields or measures your're adding to each data role when generating the dataView.
  • Expected output or specific logic you're looking to apply to a measure for a given unit inside the visual.

If I can get some further detail or clarification hopefully I can provide a more targeted answer for you.

Regards,

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

6 REPLIES 6
Anonymous
Not applicable

Hi @dm-p , 

 

The issue was that we did not prepare the data, and by the light of the information you have given I have checked the properties for the measure and found the format as : 

 

turgayseop_0-1605725788870.png

 

And by checking the metadata after setting the format, I could have seen it : 

Screenshot_11.png

 

Thank you for all your help and enlighting to find the solution.

Fantastic to hear - glad you're sorted! 🙂





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)




dm-p
Super User
Super User

Hi @Anonymous,

I'm still not 100% clear on your objectives here. How are you providing the unit information to your dataView? Is this what the dimensions data role represents in your dataViewMapping or is it a custom format string against the measure supplied as the  measures data role?

If you're setting a custom format string in the data model (e.g. "0.00 kg"), then it will come into the values array in the dataViewMapping as a raw value and its corresponding columns entry should have a format property that will contain the format string you've set up in the model.

You can then use valueFormatter from powerbi-visuals-utils-formattingutils to format the raw value using the format string from the object metadata. As there's no format property in for the measure metadata in your screenshot I'm guessing that isn't the case though.

Or, are you trying to introduce some logic into your visual to apply a denominator and add units to a measure based on a property?

What would be useful is if we could start with the following information:

  • dataRoles configuration (from capabilities.json)
  • Sample data you're adding to the visual, including any specifics around measure formatting and/or data types where applicable
  • Your dataViewMapping doesn't have any conditions on it, so confirmation on how many fields or measures your're adding to each data role when generating the dataView.
  • Expected output or specific logic you're looking to apply to a measure for a given unit inside the visual.

If I can get some further detail or clarification hopefully I can provide a more targeted answer for you.

Regards,

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)




Anonymous
Not applicable

Hello @dm-p  , 

 

the dataViewMappings

  "dataViewMappings": [
    {
      "table": {
        "rows": {
          "select": [
            {
              "for": {
                "in": "dimensions"
              }
            },
            {
              "for": {
                "in": "measures"
              }
            }
          ]
        }
      }
    }
  ]

  

and the metadata for the selected measure (Amount here) is like this :

 

Screenshot_9.png

 

so it is where I have been looking for the unit information, feel free to correct me if i am not in the right place to seek it 🙂 

 

Thanks !

dm-p
Super User
Super User

Hi @Anonymous - the dataView contains raw values and then the format for a column or measure, if applied, can be found as a property of its corresponding metadata object.

I'm not sure if this answers your question, so if not, please provide an example of your dataViewMapping and any sample data, plus expected output and I’ll see if I can advise further.

Regards,

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)




Anonymous
Not applicable

thanks for your reply, @dm-p

take for example this scenario: we have a dataset with measure "weight" whose unit is, say "kg".

  1. I guess this is more of a functional question but: where should this measure unit ("kg") be specified in Power BI?
  2. If it was specified, is there a way in the API to retrieve said measure unit?
     

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.