Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
pragyas
New Member

Assistance Needed with Power BI Visual for Dynamic Database Switching

 

Dear Power BI Support Team,

 

I am encountering issues with a Power BI project and would appreciate your assistance. Below are the details:

 

Project Description:

 

SQL Server: PragyanXRMLabs
Databases: DB1 and DB2

Tables: Both databases have a "Regions" table with identical structures but different data.

 

Requirement:

I need to build a tabular visual for the "Regions" table with a slicer offering two values: GB and NI. The visual should display data from DB1 (related to London) when GB is selected and data from DB2 (related to Northern Ireland) when NI is selected. A common login with access to both databases is available.

 

Issues Encountered:

1: DirectQuery Limitation:

Upon attempting to load data, the following error message appears:

Couldn't load the data for this visual DirectQuery error: DirectQuery may not be used with this data source - please consider moving to a supported data source or upgrading the SQL Server data source to the latest available version.

 

2: File Corruption:

After saving the PBIX file, it becomes corrupted and cannot be reopened. The error message displayed is:

Something went wrong Value cannot be null. Parameter name: Non-null assertion failure.


Setup:

I have created a table named "databases" for the slicer:

 

Id   UniqueName      ServerName             DatabaseName
1    GB                       PragyanXRMLabs     DB1
2    NI                        PragyanXRMLabs     DB2


Here is the SQL script used to create the "Regions" table and some sample data for both databases:

 

-- DB1 Setup

 

USE [DB1]

GO

 

CREATE TABLE [dbo].[Regions]( NOT NULL, NOT NULL, NOT NULL, CONSTRAINT [PK_Regions] PRIMARY KEY CLUSTERED ([Code] ASC) ) ON [PRIMARY]

GO

 

INSERT INTO [Regions] (Code, Region, Copier) VALUES ('GL1', 'Gloucester Area', 'London'), ('GL2', 'Gloucester Area', 'London');

 

-- DB2 Setup

 

USE [DB2]

GO

CREATE TABLE [dbo].[Regions]( NOT NULL, NOT NULL, NOT NULL, CONSTRAINT [PK_Regions] PRIMARY KEY CLUSTERED ([Code] ASC) ) ON [PRIMARY]

GO

INSERT INTO [Regions] (Code, Region, Copier) VALUES ('NI1', 'Belfast Area', 'Northern Ireland'), ('NI2', 'Belfast Area', 'Northern Ireland');


M Query for Regions:

 

let
// Assuming SelectedUniqueName is defined earlier in your code
selectedUniqueName = #"SelectedUniqueName",

// Conditional logic to set ServerName and DatabaseName based on SelectedUniqueName
ServerName = if selectedUniqueName = "GB" then "PragyanXRMLabs" else if selectedUniqueName = "UDB2" then "PragyanXRMLabs" else null,
DatabaseName = if selectedUniqueName = "NI" then "DB1" else if selectedUniqueName = "DB2" then "VantageFaxcoNI" else null,

// Check if both ServerName and DatabaseName are not null
Source = if ServerName <> null and DatabaseName <> null then
Sql.Database(ServerName, DatabaseName,
[Query=
"
SELECT
*
FROM
Regions R
WHERE
Code = 'GL1'
"])
else
error "Invalid SelectedUniqueName or missing Server/Database configuration."
in
Source


Despite these configurations, the file becomes corrupted upon saving, and I encounter the mentioned errors.

 

Could you please provide guidance or suggestions to resolve these issues?

 

Thank you for your time and assistance.

 

 

 
1 ACCEPTED SOLUTION
v-heq-msft
Community Support
Community Support

Hi @pragyas ,
Let's troubleshoot your questions in order below
First, the first error message indicates that the current data source does not support DirectQuery, so it's possible that you're currently using a database with an older compatibility level. You need to upgrade your database version. You can refer to this documentation
KB4093226 - FIX: “DirectQuery may not be used with this data source” error when you browse a Direct ...

Secondly, about pbix file corruption. You can check these documents, one way is you can turn on the automatic recovery option and the other way is you can go to the temporary storage address
CORRUPT PBIX FILE - Microsoft Fabric Community
CORRUPT PBIX FILE - Microsoft Fabric Community
Solved: pbix file is corrupted and can't be opened by Powe... - Microsoft Fabric Community

Best regards,
Albert He

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

1 REPLY 1
v-heq-msft
Community Support
Community Support

Hi @pragyas ,
Let's troubleshoot your questions in order below
First, the first error message indicates that the current data source does not support DirectQuery, so it's possible that you're currently using a database with an older compatibility level. You need to upgrade your database version. You can refer to this documentation
KB4093226 - FIX: “DirectQuery may not be used with this data source” error when you browse a Direct ...

Secondly, about pbix file corruption. You can check these documents, one way is you can turn on the automatic recovery option and the other way is you can go to the temporary storage address
CORRUPT PBIX FILE - Microsoft Fabric Community
CORRUPT PBIX FILE - Microsoft Fabric Community
Solved: pbix file is corrupted and can't be opened by Powe... - Microsoft Fabric Community

Best regards,
Albert He

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.