Power BI Custom Connector edit existing data

31 Views Asked by At

I'm trying to use a Power BI Custom Connector to update only the data that was changed. This means retrieve all data that was added, updated or deleted. I've built a REST API for this, returning the following JSON:

{
  [
    {
      "key": {the-record},
      "transaction": "added"//can be added, updated or deleted
    },
    {
      "key": {different-record},
      "transaction": "updated"//can be added, updated or deleted
    }
  ]
}

My goal is to use this data to perform transactions on the Power BI dataset. Right now, I have a navigation table calling the following method:

shared GetTableFromApi = (query as text) => 
    let
        json = Json.Document(Web.Contents("some-url/" & query))
    in
        Table.FromRecords(json);

How can I adapt this method so that:

  • The existing dataset is retrieved
  • If the existing dataset is null, the dataset is created with the records that were added
  • The dataset is updated with the records that were updated
  • The dataset is updated removing the records that were deleted
  • The dataset is returned

In pseudocode:

let
    dataset = getExistingDatasetOrCreateNewDataset(),
    transactions = Json.Document(Web.Contents("some-url/" & query))

    for each transaction in transactions
    if transaction.transactiontype = added
       dataset.add(transaction.record)
    if transaction.transactiontype = updated
       dataset.update(transaction.record)
    if transaction.transactiontype = deleted
       dataset.delete(transaction.record)
in
    dataset

I saw something about a masterEntries table mentioned in this post but I'm not sure how I could utilize this to achieve my desired behaviour.

0

There are 0 best solutions below