Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi Everyone,
I have created my first custom PowerBI visual using the below microsoft sample tutorial -
https://docs.microsoft.com/en-us/power-bi/developer/visuals/develop-circle-card
However, I observe that even after I remove the datafield associated with the visual, the custom visual is still showing the old/earlier data. For eg: When I add the 'Sales' field in the custom visual, it shows 340. Now when I remove it, the old data 340 is still being shown in the custom visual.
Can you please help how can this be fixed ? Does any additional code or logic required ? Or is it a bug ?
Note : When I run the 'pbiviz -V' command, it returns 3.1.15
I am posting the code inside the update function (directly taken from the tutorial provided by Microsoft in the link mentioned above) -
Solved! Go to Solution.
Hi Everyone,
I found that once I package the custom visual, it works fine.
Once I package the custom visual, and then import the custom visual in PBI Desktop, I can see that above issue is no longer faced.
For example : when I add the 'Sales' field in the custom visual, it shows 340.
Now when I remove the 'Sales field', the default landing page is shown (as it should have been).
Hi Everyone,
I found that once I package the custom visual, it works fine.
Once I package the custom visual, and then import the custom visual in PBI Desktop, I can see that above issue is no longer faced.
For example : when I add the 'Sales' field in the custom visual, it shows 340.
Now when I remove the 'Sales field', the default landing page is shown (as it should have been).
Hi @CoderMonish,
From the looks of your code, there is nothing in the update method to handle what happens for this scenario. Without all the code and project files it's hard to test with 100% certainty, but what I'm largely confident is happening is this:
.text(<string>dataView.single.value)
The SDK 'consumes' errors, so you will need to write your own code to report or handle these situations. If you surround the body of your update method's code with a try ... catch block, you'll probably be able to see this error in your browser's developer console.
To do the bare minimum to make this pass through to completion, you could use optional chaining on any statements that access the dataView so that if a property doesn't exist then the code will not silently fail. You could then add a nullish coalescing operator to display a "placeholder" value if that statement has no result, e.g.:
public update(options: VisualUpdateOptions) {
...
this.textValue
.text(<string>dataView?.single?.value ?? "(blank)")
...
this.textLabel
.text(dataView?.metadata?.columns?.[0]?.displayName ?? "[No Measure]")
...
}
If you want the visual to clear down or display something else in the absence of any data, you'd need to write an appropriate statement to check the dataView and update the visual's DOM accordingly.
Good luck,
Daniel
Proud to be a Super User!
My course: Introduction to Developing Power BI Visuals
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
Hi Daniel,
Thank you very much for reply. I am actually stuck and do not know how to proceed next. And this being a most basic sample, I hope to get this fixed soon with your and others help.
I tried below things based on your above comments, however I still face the same issue -
1) I added the try-catch block
2) I replaced the this.textValue & this.textLabel with optional chaining as you mentioned earlier.
Observation 1 : I observed that when I remove the 'Sales' measure, the last
line of the try block is getting executed successfully. So, it seems that no exception is being thrown.
Observation 2 : I am printing the 'options' variable in the last line of the try block. When I check in the Developer console, we can see that dataviews has data in it. However, the ONLY change I could notice was that dataviews[0].metadata.segment is having value 'undefined'.
Do you want me to share the visual.ts file with you ? Can you try reproducing the issue at your end,
since I am using the basic code provided in the Microsoft tutorial itself.
Thank you once again for your help.
High-level changes are as mentioned below -
public update(options: VisualUpdateOptions) {
try {
//code for re-drawing the visual
this.textValue
.text(<string>dataView?.single?.value ?? "(blank)")
// some more code . . .
this.textLabel
.text(dataView?.metadata?.columns?.[0]?.displayName ?? "[No Measure]")
//some more code . . .
console.log('Visual update', options);
console.log('I reached end of try block !!')
}
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.