Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live 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
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 |
| User | Count |
|---|---|
| 5 | |
| 5 | |
| 4 | |
| 4 | |
| 3 |