Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
Hello Everyone,
I'm using powerbi JS and powerbi-report-authoring JS to create an embed, where I generate visuals, and to these visuals I want to add in a Date Hierarchy, in this case the visual type is a tableEx, and the data I want to upload is the following:
"prototypeQuery": {
"Version": 2,
"From": [{
"Name": "p",
"Entity": "potentialTypes",
"Type": 0
}
],
"Select": [{
"HierarchyLevel": {
"Expression": {
"Hierarchy": {
"Expression": {
"PropertyVariationSource": {
"Expression": {
"SourceRef": {
"Source": "p"
}
},
"Name": "Variation",
"Property": "Date"
}
},
"Hierarchy": "Date Hierarchy"
}
},
"Level": "Year"
},
"Name": "potentialTypes.Date.Variation.Date Hierarchy.Year",
"NativeReferenceName": "Date Year"
}]}
and here is the code I use to upload the data into the visual
visual.addDataField(Object.keys(item.singleVisual.projections)[0], {
$schema: "http://powerbi.com/product/schema#hierarchyLevel",
table: dataFields.Name.split('.')[0],
hierarchy: dataFields.HierarchyLevel.Expression.Hierarchy,
hierarchyLevel: dataFields.HierarchyLevel
});
I get the following error when I run this:
{message: 'FailedToAddDataField', detailedMessage: 'Failed to add data field to role'}
I tried it without the hierarchy (replacing it with HierarchyLevel, Expression), I tried it with different Hierarchical data, I tried burning in the data, I went though the whole microsoft learn wiki (https://learn.microsoft.com/en-us/javascript/api/overview/powerbi/data-fields) but to no avail.
The only way that works is if I use column instead of the hierarchy, however the problem then that it creates all of the Date Time hierarchy, not just the one I specified, this also means that I am unable to add a normalized Date (that is not a Hierarchy) to a field programmatically, because it turns into a Hierarchy.
I am unable to add only a specific level of the Date Hierarchy to the visual programmatically; it either fails or adds the entire hierarchy, which is not the desired outcome.
Has anyone encountered this issue before or successfully added a specific level of a Date Hierarchy to a visual using Power BI's JavaScript API?
Any insights or guidance would be greatly appreciated.
Thank you in advance for your help!
Dan
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |