Power BI — Asset Types
Two queries are available: the Asset Type catalog (all types defined in your system) and Asset Type counts by location (how many assets of each type are where).
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 one of the queries below
- In the code, replace
your@email.comandYourPassword123!at the top with your Xemelgo credentials - Click Done and rename the query (e.g.,
Xemelgo Asset Types)
Query 1 — Asset Type Catalog
Returns every asset type in your Xemelgo system.
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) {
assetTypes(input: { nextToken: $n }) {
assetTypes {
id name number description
imagePath customProperties
}
nextToken
}
}",
variables = [n = nextToken]
])
])
)[data][assetTypes]
in [items = Resp[assetTypes], 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","number","description","imagePath","customProperties"},
{"ID","Name","Number","Description","Image Path","Custom Properties"})
in
Expanded
Columns returned: ID, Name, Number, Description, Image Path, Custom Properties
Query 2 — Asset Type Counts by Location
Returns on-hand, in-transit, and removed counts for each asset type at each location. Great for inventory dashboard tiles.
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) {
assetTypeMetrics(input: { nextToken: $n }) {
assetTypes {
onHandCount inTransitCount removedCount totalCount
location { id name }
type { id name }
}
nextToken
}
}",
variables = [n = nextToken]
])
])
)[data][assetTypeMetrics]
in [items = Resp[assetTypes], 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",
{"onHandCount","inTransitCount","removedCount","totalCount","location","type"},
{"On Hand","In Transit","Removed","Total","location","type"}),
WithLocation = Table.ExpandRecordColumn(Expanded,
"location", {"id","name"}, {"Location ID","Location Name"}),
WithType = Table.ExpandRecordColumn(WithLocation,
"type", {"id","name"}, {"Asset Type ID","Asset Type Name"})
in
WithType
Columns returned: On Hand, In Transit, Removed, Total, Location ID, Location Name, Asset Type ID, Asset Type Name