Suppose we have a JSON File with sample data as per below, which we want to load into the Power BI Data Model.
{
"data": [
{
"Order_ID": "1001",
"Order_Date": "2025-01-01",
"Product_Segment": "Electronics",
"Product_Name": "Laptop",
"Country": "USA",
"Sales": 1500.00
},
{
"Order_ID": "1002",
"Order_Date": "2025-01-02",
"Product_Segment": "Furniture",
"Product_Name": "Office Chair",
"Country": "Canada",
"Sales": 300.00
},
{
"Order_ID": "1003",
"Order_Date": "2025-01-03",
"Product_Segment": "Electronics",
"Product_Name": "Smartphone",
"Country": "Germany",
"Sales": 800.00
},
{
"Order_ID": "1004",
"Order_Date": "2025-01-04",
"Product_Segment": "Appliances",
"Product_Name": "Refrigerator",
"Country": "India",
"Sales": 1200.00
},
{
"Order_ID": "1005",
"Order_Date": "2025-01-05",
"Product_Segment": "Apparel",
"Product_Name": "T-shirt",
"Country": "Australia",
"Sales": 50.00
},
{
"Order_ID": "1006",
"Order_Date": "2025-01-06",
"Product_Segment": "Electronics",
"Product_Name": "Tablet",
"Country": "UK",
"Sales": 600.00
},
{
"Order_ID": "1007",
"Order_Date": "2025-01-07",
"Product_Segment": "Furniture",
"Product_Name": "Desk",
"Country": "France",
"Sales": 400.00
},
{
"Order_ID": "1008",
"Order_Date": "2025-01-08",
"Product_Segment": "Appliances",
"Product_Name": "Washing Machine",
"Country": "Japan",
"Sales": 900.00
},
{
"Order_ID": "1009",
"Order_Date": "2025-01-09",
"Product_Segment": "Apparel",
"Product_Name": "Jacket",
"Country": "Brazil",
"Sales": 120.00
},
{
"Order_ID": "1010",
"Order_Date": "2025-01-10",
"Product_Segment": "Electronics",
"Product_Name": "Smartwatch",
"Country": "Taiwan",
"Sales": 200.00
}
]
}
let
Source = Json.Document(File.Contents("C:\Users\Tamatam\Desktop\MyLearn\Power BI\Inputs\ds_Sample_Orders.json")),
Convert2Table = Table.FromRecords({Source}),
ExpandListColumns = Table.ExpandListColumn(Convert2Table, "data"),
ExpandColumnRecords = Table.ExpandRecordColumn(ExpandListColumns, "data", {"Order_ID", "Order_Date", "Product_Segment", "Product_Name", "Country", "Sales"}, {"Order_ID", "Order_Date", "Product_Segment", "Product_Name", "Country", "Sales"}),
ChangeType = Table.TransformColumnTypes(ExpandColumnRecords,{{"Order_ID", Int64.Type}, {"Order_Date", type date}, {"Product_Segment", type text}, {"Product_Name", type text}, {"Country", type text}, {"Sales", Int64.Type}})
in
ChangeType
Result: