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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Saes
Helper I
Helper I

Semanas Fiscales

Hola a todos, espero que alguien pueda ayudar - Necesito un poco de ayuda con una tabla de fechas que he creado con DAX. Incluye todo lo que necesito, excepto las semanas fiscales.

Trabajo en ventas y nuestros ejercicios comienzan en abril, pero también informamos en semanas, siendo el lunes el inicio de cada semana de ventas. El primer lunes de abril sería la semana 1 y en algunos años podemos tener 52 semanas y otros tendremos 53 semanas.

He leído bastantes publicaciones y he visto algunos vídeos, pero no puedo calcular con precisión las semanas fiscales. A continuación se muestra el código DAX - 'Número fiscal de la semana - 9999' es la columna que necesito rellenar con solo un valor numérico.

¿Alguien puede ayudar con la codificación adicional que necesito?

Gracias de antemano!

Ref - Índice de fechas ?

Var BaseCalendar ?

CALENDARIO ( FECHA ( 2000, 1, 1 ), FECHA ( 2050, 12, 31 ) )

devolución

GENERAR (

BaseCalendar,

Var BaseDate á [Fecha]

Año de VAR Fecha de año ( Fecha base )

Var MonthNumber á MES ( BaseDate )

Año VARMonthNumber á YearDate * 12 + MonthNumber - 1

REMIENDO DE VUELTA (

"Calendario del Año", YearDate,

"Year Calendar Decade", FLOOR(YearDate,10),

"Año Fiscal", Año(EOMONTH(BaseDate,-3)),

"Month Name Long", FORMAT ( BaseDate, "mmmm" ),

"Month Name Short", FORMAT ( BaseDate, "mmm" ),

"Mes Nombre Número de Calendario", MonthNumber,

"Month Name Fiscal Number", MONTH(EOMONTH(BaseDate,-3)),

"Month Calendar Quarter", QUARTER(BaseDate),

"Month Fiscal Quarter", SWITCH( TRUE(),

MesNúmero 1, 4,

MesNúmero 2, 4,

MesNúmero 3, 4,

MesNúmero 4, 1,

MesNúmero 5, 1,

MesNúmero 6, 1,

MesNúmero 7, 2,

MesNúmero 8, 2,

MesNúmero 9, 2,

MesNúmero 10, 3,

MesNúmero 11, 3,

MesNúmero 12, 3,

BLANK()),

"Week Calendar Number", WEEKNUM(BaseDate,2),

"Número Fiscal de la Semana", "9999",

"Day Name Long", FORMAT( BaseDate, "dddd" ),

"Day Name Short", FORMAT( BaseDate, "ddd" ),

"Day Number of Week", WEEKDAY( BaseDate, 2 )

)

)

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

Hola @Saes ,

Por favor, intente esto:

Fiscal Week = 
--Inputs--
VAR WeekStartsOn = "Mon"
VAR FiscalStartMonth = 4

--Calculation--
VAR FiscalFirstDay = 
    IF(
        'Ref - Date Index'[Month Name Calendar Number] < FiscalStartMonth,
        DATE(
            'Ref - Date Index'[Year Calendar]-1,
            FiscalStartMonth,
            1
        ),
        DATE(
            'Ref - Date Index'[Year Calendar],
            FiscalStartMonth,
            1
        )
    )
VAR FilteredTableCount = 
    COUNTROWS(
        FILTER(
            SELECTCOLUMNS(
                GENERATESERIES(
                    FiscalFirstDay,
                    'Ref - Date Index'[Date]
                ),
                "Dates",
                [Value]
            ),
        FORMAT([Dates],"ddd") = WeekStartsOn
        )
    )

VAR WeekNos = 
    IF(
        FORMAT(FiscalFirstDay,"ddd") <> WeekStartsOn,
        FilteredTableCount+1,        
        FilteredTableCount
    )
RETURN
WeekNos

https://www.goodly.co.in/calculate-fiscal-week-in-power-bi/

Best Regards,
Xue Ding
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

2 REPLIES 2
v-xuding-msft
Community Support
Community Support

Hola @Saes ,

Por favor, intente esto:

Fiscal Week = 
--Inputs--
VAR WeekStartsOn = "Mon"
VAR FiscalStartMonth = 4

--Calculation--
VAR FiscalFirstDay = 
    IF(
        'Ref - Date Index'[Month Name Calendar Number] < FiscalStartMonth,
        DATE(
            'Ref - Date Index'[Year Calendar]-1,
            FiscalStartMonth,
            1
        ),
        DATE(
            'Ref - Date Index'[Year Calendar],
            FiscalStartMonth,
            1
        )
    )
VAR FilteredTableCount = 
    COUNTROWS(
        FILTER(
            SELECTCOLUMNS(
                GENERATESERIES(
                    FiscalFirstDay,
                    'Ref - Date Index'[Date]
                ),
                "Dates",
                [Value]
            ),
        FORMAT([Dates],"ddd") = WeekStartsOn
        )
    )

VAR WeekNos = 
    IF(
        FORMAT(FiscalFirstDay,"ddd") <> WeekStartsOn,
        FilteredTableCount+1,        
        FilteredTableCount
    )
RETURN
WeekNos

https://www.goodly.co.in/calculate-fiscal-week-in-power-bi/

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

@Saes, creé un video sobre FY. A ver si eso encaja en tu ejemplo

https://youtu.be/euIC0dgGTNM

El archivo se adjunta después de la firma

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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 Kudoed Authors