Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more.
Get startedGrow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.
Hola, había estado buscando una solución para esto, pero no pude encontrar una. ¡Por lo general, veo lo contrario de mi problema!
Necesito escribirlo a través del código M o a través de Power Query.
Mi informe se ve así:
Empleado | Fecha de la licencia | Razón |
Micrófono | 1 sep 2022 | Fiebre |
Micrófono | Sep 2 2022 | Fiebre |
Micrófono | 5 sep 2022 | Fiebre |
Micrófono | 6 sep 2022 | Fiebre |
Micrófono | Dic 1 2020 | Jaqueca |
Quiero que el resultado se vea así:
Empleado | Primer día de licencia | Último día de permiso | Razón |
Micrófono | 1 sep 2022 | 6 sep 2022 | Fiebre |
Micrófono | Dic 1 2020 | Dic 1 2020 | Jaqueca |
Tenga en cuenta que del 1 al 6 de septiembre debe considerarse como fechas continuas (porque el 4 y 5 de septiembre son fines de semana).
Si es demasiado complicado para Power Query, ¿hay alguna manera de hacerlo como una tabla (tabla real, no virtual)/hoja en dax?
Gracias
He creado una muestra simple, por favor reer a ella para ver si te ayuda.
Crea 2 columnas.
Column first day of leave =
VAR _maxdate =
CALCULATE (
MAX ( 'Table'[Date of Leave] ),
FILTER (
ALL ( 'Table' ),
'Table'[month] = EARLIER ( 'Table'[month] )
&& 'Table'[year] = EARLIER ( 'Table'[year] )
&& 'Table'[Reason] = EARLIER ( 'Table'[Reason] )
&& 'Table'[Employee ] = EARLIER ( 'Table'[Employee ] )
)
)
VAR _mindate =
CALCULATE (
MIN ( 'Table'[Date of Leave] ),
FILTER (
ALL ( 'Table' ),
'Table'[month] = EARLIER ( 'Table'[month] )
&& 'Table'[year] = EARLIER ( 'Table'[year] )
&& 'Table'[Reason] = EARLIER ( 'Table'[Reason] )
&& 'Table'[Employee ] = EARLIER ( 'Table'[Employee ] )
)
)
VAR _datebetween =
DATEDIFF ( _mindate, _maxdate, DAY )
RETURN
IF ( _datebetween <= 7, _mindate, ( 'Table'[Date of Leave] ) )
Column last day of leave =
VAR _count =
CALCULATE (
COUNT ( 'Table'[Reason] ),
FILTER (
ALL ( 'Table' ),
'Table'[month] = EARLIER ( 'Table'[month] )
&& 'Table'[year] = EARLIER ( 'Table'[year] )
&& 'Table'[Reason] = EARLIER ( 'Table'[Reason] )
&& 'Table'[Employee ] = EARLIER ( 'Table'[Employee ] )
)
)
VAR _maxdate =
CALCULATE (
MAX ( 'Table'[Date of Leave] ),
FILTER (
ALL ( 'Table' ),
'Table'[month] = EARLIER ( 'Table'[month] )
&& 'Table'[year] = EARLIER ( 'Table'[year] )
&& 'Table'[Reason] = EARLIER ( 'Table'[Reason] )
&& 'Table'[Employee ] = EARLIER ( 'Table'[Employee ] )
)
)
VAR _mindate =
CALCULATE (
MIN ( 'Table'[Date of Leave] ),
FILTER (
ALL ( 'Table' ),
'Table'[month] = EARLIER ( 'Table'[month] )
&& 'Table'[year] = EARLIER ( 'Table'[year] )
&& 'Table'[Reason] = EARLIER ( 'Table'[Reason] )
&& 'Table'[Employee ] = EARLIER ( 'Table'[Employee ] )
)
)
VAR _datebetween =
DATEDIFF ( _mindate, _maxdate, DAY )
RETURN
IF ( _datebetween <= 7, _maxdate, ( 'Table'[Date of Leave] ) )
Si he entendido mal su significado, proporcione más detalles con su salida deseada y el archivo pbix sin información de privacidad.
Saludos
Equipo de apoyo a la comunidad _ Polly
Si esta publicación ayuda, considere Aceptarla como la solución para ayudar a los otros miembros a encontrarla más rápidamente.
Gracias por la ayuda. Solo tuve que reescribir un poco el código, ¡pero funcionó, en general! ¡Gracias de nuevo!
@ryan_mayu . Gracias por la rápida respuesta. Funcionó parcialmente, pero me di cuenta de que también tengo datos que se ven así:
Empleado B | 05 ene 2022 | Jaqueca |
Empleado B | 10 ene 2022 | Jaqueca |
El resultado debe seguir siendo el mismo y no:
Empleado B | 05 ene 2022 | 10 ene 2022 | Jaqueca |
Porque las fechas no son continuas. 😢
Tal vez pueda intentar utilizar DAX para crear una tabla
Table 2 =
VAR tbl=ADDCOLUMNS('Table',"last",maxx(FILTER('Table','Table'[Employee ]=EARLIER('Table'[Employee ])&&'Table'[Reason]=EARLIER('Table'[Reason])&&'Table'[Date of Leave]EARLIER('Table'[Date of Leave])),'Table'[Date of Leave]))
VAR tbl2=ADDCOLUMNS(tbl,"last2",if('Table'[Date of Leave] -[last]=1 || (WEEKDAY('Table'[Date of Leave])=2 && 'Table'[Date of Leave]-[last]=3),[last],blank()),"next2",if([next]-'Table'[Date of Leave]=1 || (WEEKDAY('Table'[Date of Leave])=6 && [next]-'Table'[Date of Leave]=3),[next],blank()))
VAR tbl3=ADDCOLUMNS(tbl2,"scope",if(ISBLANK([last2])&&ISBLANK([next2]),"N","Y"))
VAR tbl4=FILTER(tbl3,(ISBLANK([last2])||ISBLANK([next2]))&&[scope]="Y")
VAr tbl5=ADDCOLUMNS(tbl4,"Startdate",if(ISBLANK([last2]),'Table'[Date of Leave],maxx(FILTER(tbl4,'Table'[Date of Leave]EARLIER('Table'[Date of Leave])),'Table'[Date of Leave])))
var tbl6=SUMMARIZE(tbl5,[Employee ],[Startdate],[enddate],[Reason])
var tbl7=FILTER(tbl3,[scope]="N")
VAR tbl8=SELECTCOLUMNS(tbl7,"Employee ",[Employee ],"Startdate",[Date of Leave],"enddate",[Date of Leave],"Reason",[Reason])
return union(tbl6,tbl8)
pls ver el archivo adjunto a continuación
agradecer la ayuda! Tomé nota de sus fórmulas 😊
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.