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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Syndicate_Admin
Administrator
Administrator

Agrupación de fechas de trabajo continuas por nombre o ID

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 licenciaRazón
Micrófono1 sep 2022Fiebre
MicrófonoSep 2 2022Fiebre
Micrófono5 sep 2022Fiebre
Micrófono6 sep 2022Fiebre
MicrófonoDic 1 2020Jaqueca



Quiero que el resultado se vea así:

EmpleadoPrimer día de licenciaÚltimo día de permisoRazón
Micrófono1 sep 20226 sep 2022Fiebre
MicrófonoDic 1 2020Dic 1 2020Jaqueca


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

6 REPLIES 6
Syndicate_Admin
Administrator
Administrator

@Honne2021 ,

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] ) )

vpollymsft_0-1662536269098.png

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!

Syndicate_Admin
Administrator
Administrator

@Honne2021

tal vez puedas probar el grupo por en PQ

1.PNG2.PNG

@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 B05 ene 2022Jaqueca
Empleado B10 ene 2022Jaqueca


El resultado debe seguir siendo el mismo y no:

Empleado B05 ene 202210 ene 2022Jaqueca


Porque las fechas no son continuas. 😢


@Honne2021

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 😊

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Carousel June 2024

Check out the June 2024 Power BI update to learn about new features.

2
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors