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
johnce123
Helper I
Helper I

Ayuda de DAX Date

Tengo una situación en la que quiero contar el número de días disponibles en el año en curso.

Hay una columna de fecha de inicio de decir 01/01/2000

Fecha de finalización columna de decir 31/12/2099

Esto tendría que devolver la disponibilidad de 366 días

No obstante, se puede introducir una fecha de inicio como 01/04/2020

Fecha de finalización 31/12/2099

Esto tendría que volver 275 días.

Ayuda apreciada

6 REPLIES 6
AllisonKennedy
Super User
Super User

@johnce123 ¿Tiene una tabla DimDate? ¿En qué formato se encuentran los datos (es decir, cómo se introducen las fechas de inicio y finalización y en qué tabla y se relaciona con la tabla DimDate?)? Usted podría utilizar:
Días en el año ?

VAR _StartDate - IF(YEAR(Table[StartDate]) <YEAR(TODAY()), DATE(YEAR(TODAY()), 1, 1), Table[StartDate])

VAR _EndDate - IF(YEAR(Table[EndDate]) > YEAR(TODAY()), DATE(YEAR(TODAY()), 12, 31), Table[EndDate])

devolución
CALCULATE(COUNTROWS(ALL(DimDate)), DATESBETWEEN(_StartDate, _EndDate))


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, es una consulta directa en una base de datos SQL que es mi sistema de gestión en vivo (centro de negocios) y devuelve una fecha junto con una hora.

Gracias por tu ayuda

camargos88
Community Champion
Community Champion

@johnce123 ,

Puede utilizar esta medida:

_QtDays = 
SUMX('Table',
        IF(
            YEAR('Table'[StartDate]) <> YEAR(TODAY()), 
            DATEDIFF(DATE(YEAR(TODAY()), 1,1), DATE(YEAR(TODAY()), 12,31), DAY) + 1,
            DATEDIFF('Table'[StartDate], DATE(YEAR('Table'[StartDate]), 12,31), DAY) + 1
        ))

Capture.PNG



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



¿Se tendría también en cuenta esto si la fecha de finalización cayera antes de que finalice el año en curso

así que si mi fecha de finalización fuera 31/08/2020 calcularía desde la fecha de inicio o el comienzo del año hasta el 31/08/2020?

@johnce123 ,

Pruebe esta medida:

_QtDays = 
SUMX(
    'Table',
    VAR _tbDates = FILTER(CALENDAR('Table'[StartDate], 'Table'[EndDate]), YEAR([Date]) = YEAR(TODAY()))
    RETURN COUNTROWS(_tbDates))

Capture.PNG



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



ChrisMendoza
Resident Rockstar
Resident Rockstar

@johnce123 - Puede utilizar DATEDIFF como:

Measure Remaining Days = 
VAR beginDate = DATE(2020,4,1)
RETURN
DATEDIFF(beginDate,MAX('Table'[Date]),DAY )





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

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.