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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
DAE
Frequent Visitor

Calcular número de días de diferentes años - HELP!

Hola, tengo una tabla con la siguiente información y he calculado los días totales entre la fecha de inicio y la fecha final.

DAE_1-1714734280213.png

Ahora, necesito contar los días para cada año y que pueda filtrar por el año de los días algo así:

 

DAE_2-1714734357083.png

He intentado hacerlo con TOTALYTD, pero al no tener una sola columna con las fechas, no funciona.

HELP!

 

2 REPLIES 2
v-jialongy-msft
Community Support
Community Support

Hi @DAE 

 

First, make sure you have a date table that contains enough date ranges to cover all your possible start and end dates.

Date Table = CALENDAR (MIN('Data'[StartDate]), MAX('Data'[EndDate]))

 

To make slicing and calculating easier, you need to add the year column to the date table:

Year = YEAR('Date Table'[Date])

 

Next, you need to create a metric that calculates the number of days per year. This metric will calculate how many days there are in each year between the start date and the end date.

Days in Each Year = 
SUMX(
    VALUES('Date Table'[Year]),
    VAR CurrentYearStart = DATE('Date Table'[Year], 1, 1)
    VAR CurrentYearEnd = DATE('Date Table'[Year], 12, 31)
    VAR StartDate = MAX('Data'[StartDate])
    VAR EndDate = MIN('Data'[EndDate])
    VAR OverlapStart = MAX(CurrentYearStart, StartDate)
    VAR OverlapEnd = MIN(CurrentYearEnd, EndDate)
    RETURN
        IF(
            OverlapStart <= OverlapEnd,
            DATEDIFF(OverlapStart, OverlapEnd, DAY) ,
            0
        )
)

 

vjialongymsft_0-1714977964758.png

 

 

Best Regards,

Jayleny

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

 

Hola @v-jialongy-msft , sigo los pasos indicados, pero no funciona. Aparece el resultado en todos los días, y en la sumatoria total "Days each year" aparecen más días de los correctos. El cálculo debería ser este:

 

DAE_4-1715016537206.png

El problema es que tengo la fecha de inicio y la fecha final en la misma fila, son muchos registros, con diferentes fechas y no puedo hacer una fila por cada tramo de fechas y cada registro, ya que las combinaciones son muchisimas.

 

Envío todos los screenshots, por si me puedes dar cualquier indicación

DAE_2-1715015540770.png

¡Gracias!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.