Hi @Andy Skinner, Thank you for contacting us regarding the issue you're experiencing when querying views using the current_database() function in Power BI. I understand that the ideas work as expected within a worksheet, but no data is returned when querying from Power BI.
Based on your description, the issue may be related to privileges or how Power BI handles the current database () function.
Here are a few suggestions to help you troubleshoot the issue:
- Check privileges: Ensure that the personal access token (PAT) used by Power BI has the necessary rights to execute the current_database() function. If possible, try granting additional privileges to the PAT, such as EXECUTE or USAGE, to see if it resolves the issue.
- Modify the view: Instead of using the current_database() function in the view definition, consider using a parameterized view or a stored procedure that takes the database name as a parameter. This way, you can pass the database name as a parameter when querying from Power BI, eliminating the need for the current_database() function.
- Power BI DirectQuery mode: If you are using Power BI's DirectQuery mode, there might be limitations when using certain functions like current_database(). In this case, you could try switching to import mode, which retrieves the data from your database and stores it within the Power BI file. Remember that this might increase the size of your Power BI file and affect data refresh times.
- Check Power BI logs: Examine the logs generated by Power BI to identify any errors or issues related to the current_database() function. This might provide more insight into the root cause of the problem.
If none of these suggestions helps resolve the issue, please provide us with any error messages, logs, or relevant code snippets so we can investigate further.