Power BI — Inventory
Pulls all inventory items with part details, location, state, lot number, and expiration data.
How to Set Up
- Follow the setup steps to configure privacy settings
- In Power BI Desktop, open Transform data → Transform data
- Click New Source → Blank Query, then open Advanced Editor
- Paste the query below
- In the code, replace
your@email.comandYourPassword123!at the top with your Xemelgo credentials - Click Done and rename the query (e.g.,
Xemelgo Inventory)
M Query
let
Email = Binary.ToText(Text.ToBinary("your@email.com", TextEncoding.Utf8), BinaryEncoding.Base64),
Password = Binary.ToText(Text.ToBinary("YourPassword123!", TextEncoding.Utf8), BinaryEncoding.Base64),
Token = Json.Document(
Web.Contents("https://rest.api.xemelgo.com/login", [
Headers = [#"Content-Type" = "application/json"],
Content = Json.FromValue([email = Email, password = Password])
])
)[IdToken],
FetchPage = (nextToken as nullable text) =>
let
Resp = Json.Document(
Web.Contents("https://api.xemelgo.com/graphql", [
Headers = [Authorization = Token, #"Content-Type" = "application/json"],
Content = Json.FromValue([
query = "query($n: String) {
inventory(input: { nextToken: $n }) {
inventory {
id name description trackerSerial state
lotNumber isConsumed consumedDate expirationDate
customerPartNumber lastUpdatedDate creationDate
customProperties
part { id number name description unit quantity }
location { id name }
lastDetectedAtLocation { id name }
}
nextToken
}
}",
variables = [n = nextToken]
])
])
)[data][inventory]
in [items = Resp[inventory], nextToken = Resp[nextToken]],
Pages = List.Generate(
() => FetchPage(null),
each _ <> null,
each if _[nextToken] = null then null else FetchPage(_[nextToken]),
each _[items]
),
All = List.Combine(Pages),
Tbl = Table.FromList(All, Splitter.SplitByNothing()),
Expanded = Table.ExpandRecordColumn(Tbl, "Column1",
{"id","name","description","trackerSerial","state",
"lotNumber","isConsumed","consumedDate","expirationDate",
"customerPartNumber","lastUpdatedDate","creationDate",
"customProperties","part","location","lastDetectedAtLocation"},
{"ID","Name","Description","Tracker Serial","State",
"Lot Number","Is Consumed","Consumed Date","Expiration Date",
"Customer Part Number","Last Updated","Created",
"Custom Properties","part","location","lastDetectedAtLocation"}),
WithPart = Table.ExpandRecordColumn(Expanded,
"part",
{"id","number","name","description","unit","quantity"},
{"Part ID","Part Number","Part Name","Part Description","Part Unit","Part Quantity"}),
WithLocation = Table.ExpandRecordColumn(WithPart,
"location", {"id","name"}, {"Location ID","Location Name"}),
WithLastDetected = Table.ExpandRecordColumn(WithLocation,
"lastDetectedAtLocation", {"id","name"}, {"Last Detected Location ID","Last Detected Location Name"}),
WithDates = Table.TransformColumns(WithLastDetected, {
{"Last Updated", each if _ = null then null else #datetime(1970,1,1,0,0,0) + #duration(0,0,0,_/1000), type nullable datetime},
{"Created", each if _ = null then null else #datetime(1970,1,1,0,0,0) + #duration(0,0,0,_/1000), type nullable datetime},
{"Expiration Date", each if _ = null then null else #datetime(1970,1,1,0,0,0) + #duration(0,0,0,_/1000), type nullable datetime},
{"Consumed Date", each if _ = null then null else #datetime(1970,1,1,0,0,0) + #duration(0,0,0,_/1000), type nullable datetime}
})
in
WithDates
Columns Returned
| Column | Description |
|---|---|
| ID | Unique item identifier |
| Name | Item name |
| Tracker Serial | RFID tag serial |
| State | Current state |
| Lot Number | Lot/batch number |
| Is Consumed | Whether the item has been consumed |
| Consumed Date | Consumption date |
| Expiration Date | Expiration date |
| Customer Part Number | Customer-assigned part number |
| Last Updated / Created | Timestamps |
| Part ID / Number / Name | Associated part type details |
| Location ID / Name | Assigned location |
| Last Detected Location ID / Name | Location of last RFID read |