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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
martaredondo
Helper II
Helper II

IF/SWITCH alternative with DirectQuery

Hi everybody,

 

I'm facing a problem regarding the IF/SWITCH function because i'm using DirectQuery.

 

I created a measure and tried using IF/SWITCH but it doesn't allow me to do any comparison with my table. Then I thought instead a measure I'll use a column, but since I have to do a calculation with a measure that comes from a different table, it gives me the error: A calculated column or RLS expression on a DirectQuery table cannot reference tables from a different data source.

 

I have no more ideas and I would like to know your thoughts on this.

 

Thanks,

Marta

3 REPLIES 3
v-xuding-msft
Community Support
Community Support

Hi @martaredondo ,

 

Please share some sample data and your expected output. Then we will understand more clearly about your requirement.

 

With direct query mode, if we create a calculated column, the mode will change to mixed mode.  It means the original data is still with DQ mode. And the new column is with import mode. For this part, you could reference the document to learn more.

https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-directquery-about#modeling-limitation...

 

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @martaredondo 

 

If your tables are related, you can use RELATED() function to do it. Something like this:

 

column = IF(RELATED(table1[column1]) = "A", table2[Column2], table2[column3])

amitchandak
Super User
Super User

@martaredondo , what is your if statement. If it across two tables then you can not do like

if(Table[A]=Table2[A],,)

You can try like if(Max(Table[A])=max(Table2[A]),,)

You have to make sure you force some row context using summarize or values.

 

Refer how common row context use for date diff

refer : https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Differ...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.