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
phuongui
Frequent Visitor

Can not New Table or use DAX function in DirectQuery mode

Dear all,

 

I have a problem when use DirectQuery mode to get SQL Server Database. I turned on "Allow unrestricted measures in DirectQuery mode" but it can use another features such as, New Table or DAX function.

Direct Query Options.PNGmain.PNGPBI Version.PNG

 

How can I fix this problem?

Thanks,

Phuong

2 ACCEPTED SOLUTIONS
prateekraina
Memorable Member
Memorable Member

Hi @phuongui,

Creating a new table is not allowed in Direct Query even if you Allow Restricted stuff.

I faced the same problem at my end but since i had to create a small table of 7 rows and 2 columns, i did the following:

1. In Query Editor Section, right click on your any of the existing table and click on duplicate.
2. Rename it, Now in PowerQuery section, remove the steps, if any, after Source.
3. Edit source and wriite a custom SQL query to create your own table.

Note: By creating table i mean, use SELECT and UNION ALL to create your table.
Eg:

SELECT 1 AS [StudentID]
,'Ryan' AS [StudentName]

UNION ALL

SELECT 2 AS [StudentID]
,'David' AS [StudentName]

This approach can be useful if you have to create small table and when you can't afford to switch from DirectQuery mode to other.

Thanks !!

View solution in original post

Hi @phuongui,

As far as i know, FORMAT is not allowed while creating a 'Column' in DAX. It can be used while creating a 'Measure'
Nevertheless, if you just want to take month from Date colulm, use below DAX, it will work for sure:

MonthColumn = MONTH([Date])

Thanks !!

View solution in original post

14 REPLIES 14
prateekraina
Memorable Member
Memorable Member

Hi @phuongui,

Creating a new table is not allowed in Direct Query even if you Allow Restricted stuff.

I faced the same problem at my end but since i had to create a small table of 7 rows and 2 columns, i did the following:

1. In Query Editor Section, right click on your any of the existing table and click on duplicate.
2. Rename it, Now in PowerQuery section, remove the steps, if any, after Source.
3. Edit source and wriite a custom SQL query to create your own table.

Note: By creating table i mean, use SELECT and UNION ALL to create your table.
Eg:

SELECT 1 AS [StudentID]
,'Ryan' AS [StudentName]

UNION ALL

SELECT 2 AS [StudentID]
,'David' AS [StudentName]

This approach can be useful if you have to create small table and when you can't afford to switch from DirectQuery mode to other.

Thanks !!

But why I can not type DAX function in DirectQuery mode? I choose New Colume, just get month from date column with FORMAT keyword, it doesn't work. Maybe create new table is not necessary, even when DAX function is unavailable too... 😞

Hi @phuongui,

As far as i know, FORMAT is not allowed while creating a 'Column' in DAX. It can be used while creating a 'Measure'
Nevertheless, if you just want to take month from Date colulm, use below DAX, it will work for sure:

MonthColumn = MONTH([Date])

Thanks !!

Ohh :D, thank you so much

Most Welcome 🙂
If you think i have solved your issue, kindly accept it as a solution.

 

Thanks !!

@prateekraina

How to return month in 2 digits likes 01, 02...11, 12?

Hi @phuongui,

 

Sorry!! no clue about that,  even i searched for this solution as i wanted to sort my month names based on month numbers but due to this October being "10" always used to come after January being "1" :D.

But then i used MonthYear for sorting. Are you facing the same issue for sorting or you want to do something else?

I'm facing with YearMonth I converted in SQL Server, it's formatted as "YYYYmm" (201705). But using Month([Date]) in Power BI just convert to 5 😄 and my result when concate with year is 20175, different from data in Database (201705)....

Try this in SQL to align with Power BI:

SELECT CONCAT(DATEPART(YEAR,[TimeStamp]) , DATEPART(MONTH,[TimeStamp])) AS [YearMonth]
FROM [dbo].[Table]

It will give results like below:

201610
201611
201612
20171
20172
20173
20174
20175

Yeah, thank you very much 😄

convert to them to text first, then concatenate, then change to integer, if you have an integer it will drop the preceding 0's





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




vanessafvg
Super User
Super User

as far as i know this is not a bug but the nature of using direct query, if you want to create tables etc you need to use imported mode.





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Yes, in Imported mode everything is ok. But when I use DirectQuery mode and Allow unrestricted measures but it's not work...

correct, i think direct query mode expect you to have done most of the modelling in your source - so you will either need to push back the requirement to your source or swap to imported mode.





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




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.

Top Solution Authors