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
vika160
Helper III
Helper III

Calculation days between dates excluding weekends and holidays

I know there are tonns exaples here in a forum and on the web, but it seems that I find something for which I can not find a solution.

I have a fact table with dates and a tbldates table with the IsWorkingDayCode column that is set to 1 or 0 correctly.

It seems to be very easy, but I'm getting a mistake:

A column specified in the function call 'DATESBETWEEN' is not of type DATE. This is not supported

both columns are dates of fact table and are likned to tblDate

 

Calculated column:

Busness Days= 
CALCULATE( COUNTROWS ( 'tblDate'),
DATESBETWEEN ( 'tblDate'[DateKey], V_PBI_APPLICATION_STATUS[Open Date],
IF (
V_PBI_APPLICATION_STATUS[App End Date] <> BLANK (),
V_PBI_APPLICATION_STATUS[App End Date],
TODAY ()
)
-1 ),
'tblDate'[IsWorkingDayCode] = TRUE ,
ALL ( V_PBI_APPLICATION_STATUS )
)


 

I was trying a lot of solutions without success.

Any appreciated help.

 

Thank you!

1 ACCEPTED SOLUTION

Ok, esto es más probable porque el 'tblDate'[DateKey] no está en el mismo formato que el V_PBI_APPLICATION_STATUS[Fecha de finalización de la aplicación]

Ambos necesitan ser DateKey (como 20200714) o Date (como el 14 de julio de 2020)


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

7 REPLIES 7
AllisonKennedy
Super User
Super User

Creo que el -1 podría ser parte del problema aquí.

Tratar:

Días de Busness (Busness Days)
CALCULATE(
COUNTROWS ( 'tblDate'),
DATESBETWEEN ( 'tblDate'[DateKey], V_PBI_APPLICATION_STATUS[Fecha de apertura],
SI (
NOT(ISBLANK(V_PBI_APPLICATION_STATUS[Fecha de finalización de la aplicación])),
V_PBI_APPLICATION_STATUS [Fecha de finalización de la aplicación],
HOY ()
)
),
'tblDate'[IsWorkingDayCode] - TRUE ,
TODO ( V_PBI_APPLICATION_STATUS )
) -1

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

No, lo intenté antes. He probado su código todavía recibo el mismo error.

gracias por una respuesta rápida

¿Quieres incluir o exclusiva de las fechas de apertura y finalización? Simplemente agregue o elimine el signo igual según sea necesario en las desigualdades a continuación (como una nueva columna en la tabla V_PBI_APPLICATION_STATUS):

COLUMNA DE LA COLUMNA DE LA COLUMNA DE

VAR _maxDate - IF (
NOT(ISBLANK(V_PBI_APPLICATION_STATUS[Fecha de finalización de la aplicación])),
V_PBI_APPLICATION_STATUS [Fecha de finalización de la aplicación],
HOY ()
)

devolución
COUNTROWS (FILTER( ALL('tblDate'),
'tblDate'[DateKey]> V_PBI_APPLICATION_STATUS[Fecha de apertura]

&& 'tblDate'[DateKey]<-_maxDate
&& 'tblDate'[IsWorkingDayCode] - TRUE
)) -1


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

devuelve -1 para todas las filas.

Ok, esto es más probable porque el 'tblDate'[DateKey] no está en el mismo formato que el V_PBI_APPLICATION_STATUS[Fecha de finalización de la aplicación]

Ambos necesitan ser DateKey (como 20200714) o Date (como el 14 de julio de 2020)


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

HOLA Allison,

Lo pensé.

Tengo otra columna en la tabla Fecha que tiene el mismo formato que La fecha de finalización y la fecha de inicio. Reenlazé estos campos y lo intenté.

Tengo el mismo error.

Puedo hacer fácilmente este n sql pero es muy frustrante no puedo averiguar esto en DAX. Soy muy nuevo en DAX.

Gracias

Greg_Deckler
Super User
Super User

@vika160 - He creado Net Work Days para esto. https://community.powerbi.com/t5/Quick-Measures-Gallery/Net-Work-Days/m-p/367362#M109

Evitaría DATESBETWEEN - https://community.powerbi.com/t5/Quick-Measures-Gallery/To-bleep-With-DATESBETWEEN/m-p/1252805#M581


@ 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.