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

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.

Reply
abhay03
Helper I
Helper I

Create a Calculated Column from Different Tables in DirectQuery Mode

I have two tables that are connected from Azure SQL Database using DirectQuery mode.

 

The cardinality between these two tables is Many to One (*:1)These tables are joined on ID field and I want create to a calculated column using these two tables which satisfies the below SQL query:

 

select distinct 
case when a.Unit is NOT NULL then 'Express' Else 'Standard' End as Unit_Flag, from DB.table1 b LEFT OUTER JOIN DB.table2 a ON a.ID = b.ID and a.levelunit='High'

 

I looked at several solutions available in community but they did not seem to work with DirectQuery mode. Any help here would be very much appreciated.

5 REPLIES 5
parry2k
Super User
Super User

Try following, add new measure in Table 1 with following DAX:

 

Flag = 
var x =  CALCULATE(FIRSTNONBLANK(Table2[LevelUnit],1), Filter(Table2, Table2[LevelUnit]="High"))
return if(x = BLANK(), "Standard", "Express")


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thanks @parry2k, your solution worked well. Only challange now I have is to show this Flag measure into a Slicer and since measures can't be used in filters, this has to be calculated into or converted into a column...

Hi @abhay03,

 

Based on test, I found a lot of dax functions not available on calculated column who create in directquery mode.
I think you had to use these functions in measure.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hey @abhay03,

 

you can try this Go To

File -> Options and Settings -> Options -> Direct Query

and enable "Allow unrestricted measures ..."

 

and try to create a clacultaed column, please be aware, that this may have an impact on your query performance.

 

So, do not forget that you created a calculated column, in case there will be a performance degradation over time, with growing number of rows in your Azure SQL tables.

 

Regards

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi @TomMartens,

 

I have enabled the "Enable unrestricted measures in DirectQuery mode" but as @v-shex-msft said many functions are restricted in DirectQuery mode for a calculated column.

 

I want to calculate the above DAX query as a column to be able to use that in the filter/slicer which I'm not able to achieve.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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