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
Syndicate_Admin
Administrator
Administrator

Medida para filtrar las ventas en un intervalo de fechas específico

Hola : tengo una matriz configurada con columnas para las ventas del mes actual, las ventas de YTD y mis ventas totales del año anterior. Esta matriz utiliza una segmentación de datos para que pueda seleccionar el mes/año actual.

Para obtener el total de ventas del año anterior y omitir la segmentación de datos, utilizo esta medida:

CALCULATE (SUM ('report Charge'[TotalChargeAmount]),PREVIOUSYEAR('Date table'[Date]))

Mi problema es que también necesito una columna para el total de ventas del año anterior SIN abril, mayo, junio. He intentado todo lo que se me ocurre, con mi muy limitada comprensión dax, y simplemente no puedo averiguar cómo escribir una medida para filtrar esos meses de mi total.
Cualquier ayuda es apreciada 🙂
1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

[Editar] He enmendado la medida para que ahora funcione. La lógica estaba bien incluso antes, pero utilicé CALCULATE en lugar de CALCULATETABLE. Aquí es donde estaba el problema. Escribo medidas sin modelos, así que no tengo la oportunidad de depurar. Sólo confío en mi experiencia y si escribo tarde en la noche.... bueno, ya estoy cansado y los errores se arrastran. ¡arrepentido!

[Sales w/o April, May June] =
var PrevYearMonths =
    CALCULATETABLE(
        DISTINCT( 'Date table'[Date] ),
        PREVIOUSYEAR( 'Date table'[Date] ),
        // If you don't have a column called
        // Month Name in the dates table, use
        // anything that will identify full
        // months in each year. So the months' identifier
        // must have the same values for the same month
        // in each year. You'll have to adjust the values
        // in the curly braces as well in such a case.
        NOT 'Date table'[Month Name] IN {
            "April", "May", "June"
        },
        ALL( 'Date table' )
    )
var Result =
    CALCULATE(
        [Total Charge Amount], // the base measure
        PrevYearMonths
    )
return
    Result

View solution in original post

6 REPLIES 6
Syndicate_Admin
Administrator
Administrator

@Reine

El código estaba bien. En una línea completamente diferente utilicé CALCULATE en lugar de CALCULATETABLE. De ahí el problema. Pero la medida hace exactamente lo que estaba buscando.

Vea esto: https://dax.do/Wty121eh8QDrH2/

Syndicate_Admin
Administrator
Administrator

[Editar] He enmendado la medida para que ahora funcione. La lógica estaba bien incluso antes, pero utilicé CALCULATE en lugar de CALCULATETABLE. Aquí es donde estaba el problema. Escribo medidas sin modelos, así que no tengo la oportunidad de depurar. Sólo confío en mi experiencia y si escribo tarde en la noche.... bueno, ya estoy cansado y los errores se arrastran. ¡arrepentido!

[Sales w/o April, May June] =
var PrevYearMonths =
    CALCULATETABLE(
        DISTINCT( 'Date table'[Date] ),
        PREVIOUSYEAR( 'Date table'[Date] ),
        // If you don't have a column called
        // Month Name in the dates table, use
        // anything that will identify full
        // months in each year. So the months' identifier
        // must have the same values for the same month
        // in each year. You'll have to adjust the values
        // in the curly braces as well in such a case.
        NOT 'Date table'[Month Name] IN {
            "April", "May", "June"
        },
        ALL( 'Date table' )
    )
var Result =
    CALCULATE(
        [Total Charge Amount], // the base measure
        PrevYearMonths
    )
return
    Result

Gracias por responder 🙂 Sin embargo, esto no funciona para mí. El error es " La sintaxis de 'NOT' es incorrecta.

Era fácil de enmendar... Simplemente NO ponga delante de la expresión, no delante de IN. Ustedes, chicos, deberían pensar un poco más 🙂

En realidad lo intenté anoche y tampoco funciona. Pasé varias horas probando cosas disfías con las ideas que me dio tu código, y revisé las funciones NO y IN y nada de lo que he intentado está funcionando. El error que normalmente recibo es "La expresión true/false no especifica una columna"

@Reine

Lo siento, no te creo. Estoy casi 100% seguro de que el código es completamente funcional. He hecho esas cosas incontables veces en el pasado. ¿Tal vez deberías actualizar tu PBI? Voy a tratar de demostrar a usted que funciona correctamente usando http://dax.do. Estén atentos. Volveré.

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.