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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Alexandra_B
Helper III
Helper III

Expand Record from a column

Hello.

 

I am using an API to get the data from a Shelly device:

The script is:

let
    // Define the URL
    url = "https://shelly-<xx>-eu.shelly.cloud/device/status",

    // Define the request body
    requestBody = Text.ToBinary("id=<device_ID>&auth_key=<API_Key>"),

    // Define the headers (if needed)
    headers = [
        #"Content-Type" = "application/x-www-form-urlencoded"
    ],

    // Make the POST request
    response = Web.Contents(url, [
        Headers = headers,
        Content = requestBody
    ]),

    // Parse the JSON response
    jsonResponse = Json.Document(response),
    
    // Access the 'data' field
    data = jsonResponse[data],

    // Access the 'device_status' field
    device_status = data[device_status],

    // Convert the record to a table for easier expansion
    device_status_table = Record.ToTable(device_status)
in
    device_status_table

 

Then, my result is this:

Alexandra_B_0-1717076130318.png


I am trying to get the Record values in each column, but I don`t know how to do it quickly enough, and not one at a time, as the results of the API are like this:

 

"device_status":

{"mqtt":{"connected":false},
"switch:0":{"id":0,"aenergy":{"by_minute":[0,0,0],"minute_ts":1717071958,"total":0},"source":"init","output":false,"apower":0,"voltage":249.4,"current":0,"pf":0,"temperature":{"tC":31.3,"tF":88.4}},

"ble":[],

"id":"<device_id>",

"_updated":"2024-05-30 12:26:28",

"input:0":{"id":0,"state":false},

"v_eve:0":{"ev":"","ttl":-1,"id":0},

"eth":{"ip":null},

"ts":1717071960.41,

"code":"codeU",

"v_eve:1":{"ev":"","ttl":-1,"id":1},

"input:1":{"id":1,"state":false},

"serial":940,

"wifi":{"sta_ip":"192.x.x.x","status":"got ip","ssid":"<WiFi_name>","rssi":-65},

"cloud":{"connected":true},

"sys":{"mac":"<mac_address>","restart_required":false,"time":"11:14","unixtime":1717064091,"uptime":20691,"ram_size":238928,"ram_free":142096,"fs_size":524288,"fs_free":282624,"cfg_rev":9,"available_updates":{"stable":{"version":"1.3.2"}}}}}}

 

Please, could you share your experience?

 

Thank you.

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

You won't have much of a choice as you have nested records too.  You will need to decide which records to keep, which to throw away, and how to flatten the hierarchies.  Not really something you can do automatically.

View solution in original post

3 REPLIES 3
Alexandra_B
Helper III
Helper III

Thank you, everyone.
I ended up adding Custom Columns based on the following formula (adapted for each column):

if 
   Value.Is ([Value], type record) 
   then 
        Record.Field([Value], "connected") 
else 
    ""

 

Resulting in:

 

Alexandra_B_0-1717170512451.png  


Alexandra_B_1-1717170584860.png

 

 

Thank you for your support.

 

v-jingzhan-msft
Community Support
Community Support

Hi @Alexandra_B 

 

You can explore Record functions in Power Query from the following documentation. As all records don't share the same fields, you need to first filter the required fields and analyze which ones need to be organized into the same column. Then we can explore how to expand it more efficiently. 

Record functions - PowerQuery M | Microsoft Learn

 

If you only want to expand all records into Text format in a column, you can try the solution from below thread:

Solved: Convert record to text in power BI - Microsoft Fabric Community

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

lbendlin
Super User
Super User

You won't have much of a choice as you have nested records too.  You will need to decide which records to keep, which to throw away, and how to flatten the hierarchies.  Not really something you can do automatically.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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