# Code function for change format data from Kepware to Power BI

**URL:** https://discourse.nodered.org/t/code-function-for-change-format-data-from-kepware-to-power-bi/82978
**Category:** General
**Tags:** function-node
**Created:** [18 November 2023 04:53 UTC](https://discourse.nodered.org/t/code-function-for-change-format-data-from-kepware-to-power-bi/82978 "2023-11-18T04:53:38Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Denchai](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@Denchai](https://discourse.nodered.org/u/Denchai)
#### Post date: [18 November 2023 04:53 UTC](https://discourse.nodered.org/t/code-function-for-change-format-data-from-kepware-to-power-bi/82978/1 "2023-11-18T04:53:38Z")

</div>

Who know about code function for change format data from Kepware like picture below

 ![Screenshot 2023-11-18 115133](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/0/403eb452f76bb3d992ce967b79056106af2a27a4.png)

to API of Power BI format as  
[

{

"RANDOM\_NUM" :98.6

}

]  
Thank you.

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [18 November 2023 06:57 UTC](https://discourse.nodered.org/t/code-function-for-change-format-data-from-kepware-to-power-bi/82978/2 "2023-11-18T06:57:05Z")

</div>

??? You just write some javascript code, pick the value you are interested in from the incoming message, then you just insert it and format it in a new message that you send  
Where do you find/see 98.6 ??

---

<div class="post-metadata">

### Author: ![Denchai](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@Denchai](https://discourse.nodered.org/u/Denchai)
#### Post date: [18 November 2023 07:00 UTC](https://discourse.nodered.org/t/code-function-for-change-format-data-from-kepware-to-power-bi/82978/3 "2023-11-18T07:00:53Z")

</div>

v = RANDOM\_NUM

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [18 November 2023 07:38 UTC](https://discourse.nodered.org/t/code-function-for-change-format-data-from-kepware-to-power-bi/82978/4 "2023-11-18T07:38:26Z")

</div>

In a change node you can  
set `msg.` `payload[0].RANDOM_NUM`  
to value of `msg.` `payload.values[0].v`

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path/value to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [18 November 2023 07:42 UTC](https://discourse.nodered.org/t/code-function-for-change-format-data-from-kepware-to-power-bi/82978/5 "2023-11-18T07:42:20Z")

</div>

There are many ways, however, in the interest of speed, a function node containing ...

```auto
msg.payload = [{ RANDOM_NUM: msg.payload.values[0].v } ]
return msg

```

... will work.

Also possible with a `change` node, a `template` node and others.

* * *

In future, please post sample data instead of a screenshot (we can use sample data in a working example without having to type stuff out)

## Canned tips for newcomer

### Getting the EXACT path (like `msg.payload.values[0].v`) and copying usable data

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

### How to post Code properly

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

### Recommended essential playlist to get up to speed quickly

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

### Author: ![Denchai](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@Denchai](https://discourse.nodered.org/u/Denchai)
#### Post date: [18 November 2023 07:57 UTC](https://discourse.nodered.org/t/code-function-for-change-format-data-from-kepware-to-power-bi/82978/6 "2023-11-18T07:57:52Z")

</div>

> [@Steve-Mcl](#):
>
> ```auto
> msg.payload = [{ RANDOM_NUM: msg.payload.values[0].v } ]
> return msg
> 
> ```

Thank you very much. It very clear.

---

<div class="post-metadata">

### Author: ![Denchai](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@Denchai](https://discourse.nodered.org/u/Denchai)
#### Post date: [18 November 2023 07:58 UTC](https://discourse.nodered.org/t/code-function-for-change-format-data-from-kepware-to-power-bi/82978/7 "2023-11-18T07:58:29Z")

</div>

Thank you very much. It very clear.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [2 December 2023 07:59 UTC](https://discourse.nodered.org/t/code-function-for-change-format-data-from-kepware-to-power-bi/82978/8 "2023-12-02T07:59:04Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
