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

Cómo restringir el promedio móvil hasta la semana pasada

He creado un DAX para 7 días de media móvil como -

Casos O 7 Días Promedio Rodante ?
AVERAGEX(
DATESINPERIOD( DimDate[Fecha], LASTDATE( DimDate[Fecha]), -7, DIA ), [O Casos (Total)] )
¿Cómo restringir la fecha hasta el sábado pasado? Los datos actuales no deben estar ahí. Idealmente, necesito 7 días de promedio rodante (Dom-Sab) datos de la semana completa. Así que si hoy es lunes (21 de diciembre), quiero el último promedio de 7 días rodando hasta el 19 de diciembre.
3 REPLIES 3
v-deddai1-msft
Community Support
Community Support

No @monikamishra ,

Por favor, agregue una columna de día de la semana en la tabla de fechas:

WEEKDAY = WEEKDAY(Dim_Date[Date],2)

A continuación, intente utilizar la siguiente medida:

OR Cases 7 Day Rolling Average =
VAR A =
    CALCULATE (
        MAX ( 'Dim_Date'[Date] ),
        FILTER (
            ALL ( Dim_Date ),
            Dim_Date[Date] <= MAX ( Dim_Date[Date] )
                && Dim_Date[WEEKDAY] > 6
        )
    )
VAR NUM =
    MAX ( Dim_Date[Date] ) - A + 1
VAR TOTALVALUE =
    CALCULATE (
        [OR Cases (Total)],
        FILTER (
            ALL ( Dim_Date ),
            Dim_Date[Date] >= A
                && Dim_Date[Date] <= MAX ( Dim_Date[Date] )
        )
    )
RETURN
    TOTALVALUE / NUM

También puede consultar el archivo pbix de ejemplo: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/Ef5zxVgk6VBOqAeN5s...

Si este post ayuda, entonces considera Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

Saludos

Dedmon Dai

AllisonKennedy
Super User
Super User

¿Siempre quieres Sun-Sat? A continuación, deberá usar WeekNumber. Agregue WeekNumber a su tabla DimDate si aún no la tiene.

O Casos de la semana anterior Promedio ?
_MaxDate - MAX(DimDate[Fecha])
_weekNum á MAXX(FILTER(DimDate, DimDate[Date] á _MaxDate), DimDate[WeekNumber])
devolución
AVERAGEX(
FILTER( DimDate, DimDate[WeekNum] á _weekNum-1 ), [OR Cases (Total)] )
Esto no funcionará durante el nuevo año, por lo que realmente debe agregar algunas condiciones si _weekNum 1, entonces usted tendrá que utilizar
devolución
AVERAGEX(
FILTER( DimDate, DimDate[WeekNum] á 53 ), [O Casos (Total)] )

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

amitchandak
Super User
Super User

@monikamishra , Piensa que necesitas la semana pasada, por favor revisa mi blog

Power BI — Semana a semana y WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

o tratar como ejemplo

Los últimos siete hasta el final de la semana

la semana pasada .
Fecha de inicio de la semana: maxx(allselected('Date'),'Date'[Date])+-7
Fecha de fin de semana: maxx(allselected('Date'),'Date'[Date])+7-1*WEEKDAY('Date'[Date],2) //sunday is week end

devolución
CALCULATE(SUM(Sales[Net Sales]),FILTER(all('Date'),'Date'[Date]>'_min && 'Date'[Date]<'_max))

usar WEEKDAY('Date'[Date],1) para el sábado

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