I have been able to pull down an audit table from Dynamics 365 and load it into Power BI by selecting Get Data, choosing the odata option and using url/api/data/v9.1/audits
. I see the column RetrieveAuditDetails
, but I don't understand why all the values say Function. Is there a way to extend this to show the old value/new value in the same way you can change, for example, UserIDs to be extended to the full name?

- 22,364
- 14
- 59
- 168

- 546
- 11
- 24
1 Answers
When it comes to audit data, OData/Web API REST endpoint is not so friendly in PowerBI due to the reason that the audit data is stored as delimited values in database. Refer my answer in this SO thread.
If it's a javascript or .net application you can do iterative call using RetrieveAuditDetails
function to fetch full details after getting full list using https://crmdev.crm.dynamics.com/api/data/v9.1/audits
. This is why you are seeing as Function in there.
For example:
var parameters = {};
var entity = {};
entity.id = "5701259e-59b8-e911-bcd0-00155d0d4a79";
entity.entityType = "audit";
parameters.entity = entity;
var retrieveAuditDetailsRequest = {
entity: parameters.entity,
getMetadata: function() {
return {
boundParameter: "entity",
parameterTypes: {
"entity": {
"typeName": "mscrm.audit",
"structuralProperty": 5
}
},
operationType: 1,
operationName: "RetrieveAuditDetails"
};
}
};
Xrm.WebApi.online.execute(retrieveAuditDetailsRequest).then(
function success(result) {
if (result.ok) {
var results = JSON.parse(result.responseText);
}
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
Update:
On further analysis - there is no big difference between the output schema from the above RetrieveAuditDetails
query targeting single auditid
or the below filtered audits
query targeting single recordid
.
https://crmdev.crm.dynamics.com/api/data/v9.1/audits?$filter=_objectid_value eq 449d2fd8-58b8-e911-a839-000d3a315cfc
The fact is either web api or fetchxml, the resultset cannot fetch the important column changedata
which contains the changed field values - due to the restriction: Retrieve can only return columns that are valid for read. Column : changedata. Entity : audit
I get this in FetchXML builder:
There is another approach but not PowerBI compatible anyway, using RetrieveRecordChangeHistory
to target the recordid
to get all the audit collections with old & new values. Example below:
https://crmdev.crm.dynamics.com/api/data/v9.0/RetrieveRecordChangeHistory(Target=@Target)?@Target={%22accountid%22:%22449d2fd8-58b8-e911-a839-000d3a315cfc%22,%22@odata.type%22:%22Microsoft.Dynamics.CRM.account%22}

- 22,364
- 14
- 59
- 168
-
Hi Arun, I have a question for understanding, as we do know Audit has RetrieveAuditDetails function wherein we can find more details. But then how do we tackle that w.r.t PowerBI and Webapi call. I tried using fetchxml and as we know only function is what retrieved. so does that mean there is no direct fecth/webapi call to get data rather one extra step in between is needed? – AnkUser Aug 21 '19 at 08:07
-
2@AnkUser pls see my update. unfortunately pushing all the raw data to staging table and massage it or massage in code before dump in staging table are the options - either way we have to put it in a staging table to consume but not direct url accessible like other entities :( – Arun Vinoth-Precog Tech - MVP Aug 21 '19 at 16:21
-
@ArunVinoth so with your statement above, could I, in theory, use a separate entity in D365 to get the values, and then pull that entity/table into Power BI? – SQLHound Aug 22 '19 at 13:23
-
@SQLHound that could be an overhead, why not some staging table on an on-premise sql used for replication (if you already have one).. – Arun Vinoth-Precog Tech - MVP Aug 22 '19 at 14:00
-
@ArunVinoth the customer requires the data to stay in the cloud. I realize that I am pulling the data out when I design on the Power BI desktop, but this is all development. When we advance the report to production it will all stay in the cloud. – SQLHound Aug 22 '19 at 14:07
-
@SQLHound try Data export service to replicate into Azure SQL server then.. – Arun Vinoth-Precog Tech - MVP Aug 22 '19 at 14:09
-
Coming back around on this, so the staging table can't be brought in to Power BI by, say, M? I would think if you could program for it in javascript, you could program it in something Power BI can understand. – SQLHound Sep 04 '19 at 16:04