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

Datediff: Dias de licencias entre meses

Hola Comunidad, tengo una cuestion en mi reporte. necesito extraer la cantidad de dias que licencias que se toman las personas, pero saber cuando son esos dias en dicho mes. 

JoseRibasP_0-1679417535187.png

Como ejemplo en la imagen, tengo el INICIO y FIN de las licencias. necesito extraer la cantidad de dias que se toman en cada mes. si bien, las unidades de licencias me sirven, necesitaria calcular en una medida los dias que se toman en enero y en febrero, como se ve en la 2 fila, tiene 36 dias de licencia, pero en enero son 31 dias y en febrero son 5.

muchas gracias de antemano

1 ACCEPTED SOLUTION

@JoseRibasP 

Then try

Days Count =
VAR MaxDate =
MAX ( 'Date'[Date] )
VAR MinDate =
MIN ( 'Date'[Date] )
RETURN
SUMX (
'Table',
DATEDIFF (
MAX ( 'Table'[INICIO], MinDate ),
MIN ( 'Table'[FIN], MaxDate ),
DAY
) + 1
)

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

Hi @JoseRibasP 

I assume you have a date table and you are slicing by month. Then try

Days Count =
VAR MaxDate =
MAX ( 'Date'[Date] )
VAR MinDate =
MIN ( 'Date'[Date] )
RETURN
SUMX (
'Table',
DATEDIFF (
MAX ( 'Table'[INICIO], MinDate ),
MIN ( 'Table'[FIN], MaxDate ),
DAY
)
)

 

The count of days generates a lower result for me, even without applying filters using the calculate measure (excluding endless absences and leaves), the result is still lower.


Dax Result for january :

JoseRibasP_0-1679421421496.png

 

Excel Result for january: 

JoseRibasP_1-1679421524942.png

 




 

@JoseRibasP 

Then try

Days Count =
VAR MaxDate =
MAX ( 'Date'[Date] )
VAR MinDate =
MIN ( 'Date'[Date] )
RETURN
SUMX (
'Table',
DATEDIFF (
MAX ( 'Table'[INICIO], MinDate ),
MIN ( 'Table'[FIN], MaxDate ),
DAY
) + 1
)

Thanks you @tamerj1! the measure is completed!

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.

Top Solution Authors