cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Anonymous
Not applicable

Direct Query SQL: Load data if slicer has one selection

Hello everyone,

 

I have a table which should only show data from a Direct Query SQL table when a slicer with the column "UserId" contains one selection.

After researching, there was no solution to be found. However, I realized something: I could change the SQL statement which was currently: "SELECT UserId, Name, Age FROM Datatable" to something like (note: It's psuedoCode): "IF( DISTINCTCOUNT(UserId) is 1) THEN SELECT UserId, Name, Age FROM Datatable ELSE SELECT nothing". Normally, this would cause nothing to be shown in the visual. However, this is Direct Query and not Import. Because PowerBI queries efficiently and considers slicer selection and filter in their SQL queries, BI would (hopefully) include something like "WHERE UserId = '0004'" (If the value "0004" is selected).

 

Can anyone tell me:

- if this could work

- how the pseudo-code has to be formullated in SQL

 

Thanks in advance!

2 REPLIES 2
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can create a measure as below and make the visual filtered by it like that to work around.

Me = var als =CALCULATE(DISTINCTCOUNT('Product'[Category]),ALLSELECTED('Product'))
var al = CALCULATE(DISTINCTCOUNT('Product'[Category]),ALL('Product'))
return
IF(al=als,BLANK(),1)

Capture.PNG

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Hello @v-frfei-msft ,

 

I have to avoid using measures because with them, my visuals won't load fast anymore. Also, while this causes the visual not to show anything, data will still be loaded in the background, which makes other queries to the database slow.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors