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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
felipevinasco
Regular Visitor

Ultimo y penultimo día laboral

Buenas tardes,

Tengo una base de datos de solicitudes que se radican a diario y necesito tener la suma de los solicitudes que se radicaron el día anterior y el trasanterior de los días laborales, en mi modelo de datos ya tengo una tabla calendario vinculada con otra tabla de los días festivos (o no laborales) la cual relacione y cree una nueva columna llamada "TIPO DE DÍA" que me indica que para los días sabados, domingos o festivos me coloque "Día No Laboral" y para los que no, "Día Laboral".

 

Basado en esto logre calcular la fecha del ultimo día laboral de la siguiente manera = CALCULATE(MAX('BASE'[Fecha_Solicitud]) , Calendario[TIPO DE DÍA] = "Día Laboral")

 

Pero no he conseguido obtener el penultimo día laboral, teniendo en cuenta que para el reporte que se genera el día lunes, en la base de datos que se ejecuta hay solicitudes del día sabado y domingo. Pero yo necesito las solicitudes del día anterior y trasanterior de los días laborales, es decir las solitudes del día viernes (que seria el ultimo día laboral) y las solicitudes del día jueves (que seria el penultimo día laboral)

 

Les agradecieria mucho si me pueden colaborar, gracias.

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @felipevinasco ,

 

I create a sample to have a test in myside. In my sample, date is from 2023/01/01 to today (2023/02/21). 

Holiday:

RicoZhou_0-1676966354064.png

Calendar:

Calendar = ADDCOLUMNS(CALENDAR(DATE(2023,01,01),TODAY()),"Weekday",WEEKDAY([Date],2))

DayType column:

DAY_TYPE = 
IF(OR('Calendar'[Weekday] IN {6,7},'Calendar'[Date] IN VALUES(Holiday[Holiday])),"Non-Working Day","Working Day")

RicoZhou_1-1676966439251.png

You can try measure as below.

Last Working Day = 
VAR _GENERATE_DAY =
    TODAY ()
VAR _GENERATE_DAY_TYPE =
    CALCULATE (
        MAX ( 'Calendar'[DAY_TYPE] ),
        FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] = _GENERATE_DAY )
    )
VAR _RESULT1 =
    CALCULATE (
        MAX ( 'Calendar'[Date] ),
        FILTER ( ALL ( 'Calendar' ), 'Calendar'[DAY_TYPE] = "Working Day" )
    )
VAR _RESULT2 =
    CALCULATE (
        MAX ( 'Calendar'[Date] ),
        FILTER (
            ALL ( 'Calendar' ),
            AND ( 'Calendar'[DAY_TYPE] = "Working Day", 'Calendar'[Date] < _RESULT1 )
        )
    )
RETURN
    IF ( _GENERATE_DAY_TYPE <> "Working Day", _RESULT1, _RESULT2 )
Penultimate Working Day = 
CALCULATE (
    MAX ( 'Calendar'[Date] ),
    FILTER (
        ALL ( 'Calendar' ),
        AND (
            'Calendar'[DAY_TYPE] = "Working Day",
            'Calendar'[Date] < [Last Working Day]
        )
    )
)

Result is as below.

RicoZhou_2-1676966458057.png

 

Best Regards,
Rico Zhou

 

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

View solution in original post

1 REPLY 1
v-rzhou-msft
Community Support
Community Support

Hi @felipevinasco ,

 

I create a sample to have a test in myside. In my sample, date is from 2023/01/01 to today (2023/02/21). 

Holiday:

RicoZhou_0-1676966354064.png

Calendar:

Calendar = ADDCOLUMNS(CALENDAR(DATE(2023,01,01),TODAY()),"Weekday",WEEKDAY([Date],2))

DayType column:

DAY_TYPE = 
IF(OR('Calendar'[Weekday] IN {6,7},'Calendar'[Date] IN VALUES(Holiday[Holiday])),"Non-Working Day","Working Day")

RicoZhou_1-1676966439251.png

You can try measure as below.

Last Working Day = 
VAR _GENERATE_DAY =
    TODAY ()
VAR _GENERATE_DAY_TYPE =
    CALCULATE (
        MAX ( 'Calendar'[DAY_TYPE] ),
        FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] = _GENERATE_DAY )
    )
VAR _RESULT1 =
    CALCULATE (
        MAX ( 'Calendar'[Date] ),
        FILTER ( ALL ( 'Calendar' ), 'Calendar'[DAY_TYPE] = "Working Day" )
    )
VAR _RESULT2 =
    CALCULATE (
        MAX ( 'Calendar'[Date] ),
        FILTER (
            ALL ( 'Calendar' ),
            AND ( 'Calendar'[DAY_TYPE] = "Working Day", 'Calendar'[Date] < _RESULT1 )
        )
    )
RETURN
    IF ( _GENERATE_DAY_TYPE <> "Working Day", _RESULT1, _RESULT2 )
Penultimate Working Day = 
CALCULATE (
    MAX ( 'Calendar'[Date] ),
    FILTER (
        ALL ( 'Calendar' ),
        AND (
            'Calendar'[DAY_TYPE] = "Working Day",
            'Calendar'[Date] < [Last Working Day]
        )
    )
)

Result is as below.

RicoZhou_2-1676966458057.png

 

Best Regards,
Rico Zhou

 

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

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.