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
Anonymous
Not applicable

How to use Calculate and Countrows in Direct Query Mode? It keeps saying not a function

Hi there,
 
I am trying to convert a dashboard from import to direct query mode and realized a calculated column created is not translating easily due to limitation of DAX functions with Direct Query mode. Specifically, I keep getting the error that "Calculate it not a function", "Countrows is not a function", and "Datesbetween" is not a function.
 
Anyone know another function that will work the same in direct query? This was the original dax to calculate hours which takes into account work day hours.... 
 
The reason I need this as a calculated column is I need it as a value for a line chart where I am visualizing putaway hours by date. 
 

 

PTWY Hrs = 
var shiftstart = 6 //shift start at 6am
var shiftend = 17 //shift end at 5pm
var wrkdyhours = shiftend-shiftstart //11 workday hours
var wrkdyafterhours = 24-(shiftend-shiftstart) //13 after shift hours on 11 hour workday
return
if('INBD Items'[Putaway Date].[Date]='INBD Items'[GR Date].[Date],//if putaway done on same day as gr
DATEDIFF('INBD Items'[GR Date],'INBD Items'[Putaway Date],MINUTE)/60,//then calculate the minutes
(DATEDIFF('INBD Items'[GR Date],'INBD Items'[Putaway Date],MINUTE)-(//else calculate minutes and subtract non working hours
    CALCULATE(countrows('Date'),DATESBETWEEN('Date'[Date],'INBD Items'[GR Date],'INBD Items'[Putaway Date]),'Date'[IsWorkingDay]=FALSE())*24*60+ //calculate non working day convert to minutes to subtract
    (CALCULATE(countrows('Date'),DATESBETWEEN('Date'[Date],'INBD Items'[GR Date],'INBD Items'[Putaway Date]),'Date'[IsWorkingDay]=TRUE())-1)*wrkdyafterhours*60 //calculate  after hour minutes to subtract
))/60//convert to hours
)​

 

3 REPLIES 3
v-luwang-msft
Community Support
Community Support

Hi @Anonymous ,

Has your problem been solved, if so, please consider Accept a correct reply as the solution or share your own solution to help others find it.

Best Regards
Lucien

v-luwang-msft
Community Support
Community Support

Hi @Anonymous ,

It is possible to add calculated columns or do some actions in query editor when there's a direct query connection. But there're some limitations for it. Below is the articles about these limitations for your reference.

https://docs.microsoft.com/en-us/power-bi/desktop-directquery-about

http://radacad.com/directquery-live-connection-or-import-data-tough-decision

 

 

Best Regards,

Lucien

Greg_Deckler
Super User
Super User

@Anonymous What about converting it to a measure? Then you won't have those restrictions.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.