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

Ventas acumuladas en el último mes

Hola a todos,

Soy bastante nuevo en DAX y estoy tratando de crear una medida para las ventas acumuladas en el último mes (y he probado un montón de soluciones proporcionadas en este foro) pero todavía no estoy obteniendo el resultado que estoy buscando.

¿Podría alguien decirme lo que estoy haciendo mal, por favor?

SalesCumu_MTD = 
VAR mth = 4
    --MONTH(LASTDATE('Fact'[InvoiceDate]))
VAR yr = 2020
    --YEAR(LASTDATE('Fact'[InvoiceDate]))
VAR dayofmth = 21
    -- DAY(LASTDATE('Fact'[InvoiceDate]))
RETURN
    CALCULATE (
        SUM ( 'Fact'[SalesValue]),
        FILTER (
            ALL(DimPeriod),
            DimPeriod[FiscalMthNo] = mth
            && DimPeriod[FiscalYrNo] = yr
            && DimPeriod[FiscalDayNo_OfMth] <= dayofmth
        )
    )

Entiendo que si no incluyo el ALL(DimPeriod) voy a obtener las ventas diarias de cada día en ese mes. Pero cuando incluyo TODO, me está dando las ventas totales en ese mes... lo que realmente tiene sentido, pero no es lo que estoy buscando. Así que mi pregunta es, ¿cómo obtengo las ventas diarias acumuladas para cada día?

Capture.JPG

¡Cualquier ayuda sería apreciada! ¡Gracias de antemano!

1 ACCEPTED SOLUTION

@psiripun

He modificado la lógica.

Capture.JPG

Tienes que activar la jerarquía de fechas

Capture.JPG

MTD_sales = CALCULATE(SUM('Table'[Sales]),DATESMTD('Table'[InvoiceDate].[Date]))
//if you are not using data hierarchy .[Date] not required. But InvoiceDate should be date type
MTDSales = TOTALMTD(SUM('Table'[Sales]),'Table'[InvoiceDate].[Date])
//if you are not using data hierarchy .[Date] not required. But InvoiceDate should be date type



¿Respondí a tu pregunta? ¡Marca mi puesto como solución!
Apreciar con un kudos
🙂


Regards,
Nandu Krishna

View solution in original post

3 REPLIES 3
nandukrishnavs
Super User
Super User

@psiripun

No está seguro acerca de los datos existentes y la salida esperada.

He preparado un conjunto de datos de muestra y medidas.

Monthly Sales = SUM('Table'[Sales])
YTD_sales = CALCULATE(SUM('Table'[Sales]),DATESYTD('Table'[InvoiceDate].[Date]))
YTDSales = TOTALYTD(SUM('Table'[Sales]),'Table'[InvoiceDate].[Date])

Capture.JPG

Avísame si tienes alguna pregunta.



¿Respondí a tu pregunta? ¡Marca mi puesto como solución!
Apreciar con un kudos
🙂


Regards,
Nandu Krishna

@nandukrishnavs

¡Muchas gracias por su sugerencia! Intenté replicar las fórmulas con mis datos, pero todavía no estoy obteniendo el resultado que estoy buscando.

Salida esperada: Ventas diarias acumuladas para el último mes, abril de 2020

Capture.JPG

Test_Sales_MTD = CALCULATE(SUM('Fact'[SalesValue]),DATESMTD('Fact'[InvoiceDate]))
Test_Sales_MTD2 = TOTALMTD(SUM('Fact'[SalesValue]),'Fact'[InvoiceDate])
Sales_MTD = 
VAR mth = 4
VAR yr= 2020
RETURN
    CALCULATE (
        SUM ( 'Fact'[SalesValue]),
        FILTER (
            (DimPeriod),
            DimPeriod[FiscalMthNo] = mth
                && DimPeriod[FiscalYrNo] = yr
        )
    )

Hay algunos problemas aquí:

1. Los valores son de las ventas en cada día; no se agregan acumulativamente.

2. Algunos días en los que no hay valor de ventas (como el 5 o 6 de abril), la fórmula es obtener el valor de ventas del mes anterior en lugar de dejar la fila en blanco.

¿Podrían ayudar a aconsejar lo que me estoy perdiendo?

¡Muchas gracias!

@psiripun

He modificado la lógica.

Capture.JPG

Tienes que activar la jerarquía de fechas

Capture.JPG

MTD_sales = CALCULATE(SUM('Table'[Sales]),DATESMTD('Table'[InvoiceDate].[Date]))
//if you are not using data hierarchy .[Date] not required. But InvoiceDate should be date type
MTDSales = TOTALMTD(SUM('Table'[Sales]),'Table'[InvoiceDate].[Date])
//if you are not using data hierarchy .[Date] not required. But InvoiceDate should be date type



¿Respondí a tu pregunta? ¡Marca mi puesto como solución!
Apreciar con un kudos
🙂


Regards,
Nandu Krishna

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.