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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

División Runnig

Hola Expertos,
Estaba tratando de crear medida en DAX en los siguientes datos:
Nombre de la tabla: Muestra

fecha de Product_id My_price venta other_price el otro precio indexado
12345 20200701 100 75 120
12345 20200704 100 22 130
12345 20200705 100 56 140
12345 20200706 100 52 140
12345 20200731 100 99 140
12345 20200801 100 24 150
12345 20200809 100 58 120
12345 20200907 100 24 200
12345 20200908 100 39 120
12345 20200908 100 56 100
12345 20200908 100 64 125

Fórmula para otro precio indexadoother_price/first_other_price_in_the_month * 100
A continuación se espera la salida:
fecha de Product_id My_price venta other_price el otro precio indexado
12345 20200701 100 75 120 100
12345 20200704 100 22 130 108.3333333
12345 20200705 100 56 140 116.6666667
12345 20200706 100 52 140 116.6666667
12345 20200731 100 99 140 116.6666667
12345 20200801 100 24 150 100
12345 20200809 100 58 120 80
12345 20200907 100 24 200 100
12345 20200908 100 39 120 60
12345 20200908 100 56 100 50
12345 20200908 100 64 125 62.5


En el ejemplo anterior Para:
Mes de Julio first_other_price_in_the_month-120 (que se utilizará en la fórmula para los datos del mes de julio)
Mes de Agosto first_other_price_in_the_month-150 (para ser utilizado en la fórmula para los datos de Augmonth)
Mes de Septiembre first_other_price_in_the_month 200 (que se utilizará en la fórmula para los datos del mes de septiembre)

Nota: Tengo 100 Product_ID diferentes, en el ejemplo anterior he considerado solamente una product_id.
Cualquier ayuda o sugerencia en el código DAX para rellenar el precio indexado de otro precio sería muy apreciado.
Gracias

2 ACCEPTED SOLUTIONS
edhans
Super User
Super User

Necesita una tabla de fechas para hacer esto correctamente @bchhugwani que he incluido en el archivo PBIX que estoy compartiendo a continuación. Esta medida creo que devolverá lo que quieras.

Measure = 
VAR varCurrentDate =
    MAXX(
        'Table',
        RELATED('Date'[Date])
    )
VAR varCurrentMonthYear =
    YEAR( varCurrentDate )
        * 100
            + MONTH( varCurrentDate )
VAR varCurrentMonth =
    MAXX(
        'Table',
        RELATED( 'Date'[Month Year Sort] )
    )
VAR varFirstDateOfMonth =
    CALCULATE(
        MIN( 'Table'[date] ),
        REMOVEFILTERS( 'Table'[date] ),
        FILTER(
            'Date',
            'Date'[Month Year Sort] = varCurrentMonthYear
        )
    ) 
VAR varFirstOtherPrice =
    CALCULATE(
        MAX( 'Table'[other_price] ),
        'Table'[date] = varFirstDateOfMonth,
        REMOVEFILTERS( 'Table'[date] )
    ) 
VAR varOtherPrice =
    MAX( 'Table'[other_price] )
VAR Result =
    DIVIDE(
        varOtherPrice,
        varFirstOtherPrice,
        0
    ) * 100
RETURN
    Result

edhans_0-1596472213966.png

Mi archivo PBIX está aquí.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

Hola @Antara ,

Puede intentar crear una medida como se indica a continuación:

avg_measure =
VAR _sumofSales =
    SUMX (
        FILTER (
            ALL ( 'Table'[date], 'Table'[Product_id] ),
            'Table'[date] = MAX ( 'Table'[date] )
        ),
        [Measure]
    )
VAR _countofP =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Product_id] ),
        FILTER ( 'Table', 'Table'[date] = MAX ( 'Table'[date] ) )
    )
RETURN
    DIVIDE ( _sumofSales, _countofP, 0 )

Saludos

Rena

Community Support Team _ Rena
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

3 REPLIES 3
edhans
Super User
Super User

Necesita una tabla de fechas para hacer esto correctamente @bchhugwani que he incluido en el archivo PBIX que estoy compartiendo a continuación. Esta medida creo que devolverá lo que quieras.

Measure = 
VAR varCurrentDate =
    MAXX(
        'Table',
        RELATED('Date'[Date])
    )
VAR varCurrentMonthYear =
    YEAR( varCurrentDate )
        * 100
            + MONTH( varCurrentDate )
VAR varCurrentMonth =
    MAXX(
        'Table',
        RELATED( 'Date'[Month Year Sort] )
    )
VAR varFirstDateOfMonth =
    CALCULATE(
        MIN( 'Table'[date] ),
        REMOVEFILTERS( 'Table'[date] ),
        FILTER(
            'Date',
            'Date'[Month Year Sort] = varCurrentMonthYear
        )
    ) 
VAR varFirstOtherPrice =
    CALCULATE(
        MAX( 'Table'[other_price] ),
        'Table'[date] = varFirstDateOfMonth,
        REMOVEFILTERS( 'Table'[date] )
    ) 
VAR varOtherPrice =
    MAX( 'Table'[other_price] )
VAR Result =
    DIVIDE(
        varOtherPrice,
        varFirstOtherPrice,
        0
    ) * 100
RETURN
    Result

edhans_0-1596472213966.png

Mi archivo PBIX está aquí.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Gracias @edhans por la rápida respuesta. Te lo agradezco mucho. Si en caso de que en caso de que quiera realizar el promedio en la parte superior de la medida a través de la fecha (independientemente de Product_id). ¿Podemos crear una medida media además de esta medida?

En resumen,

Para mostrar la fecha, avg_of_Measure_created_below en un objeto visual de tabla. Si tenemos fecha como 20200701 para 2 Product_ID (digamos 12345 y 56789) y Measure (creado usando la mención de fórmula por @edhans ) como valor 100 y 200 entonces la tabla visual debe mostrar:

Salida:

fecha avg_measure

20200701 150

Cualquier ayuda o sugerencia sería útil

Gracias

Hola @Antara ,

Puede intentar crear una medida como se indica a continuación:

avg_measure =
VAR _sumofSales =
    SUMX (
        FILTER (
            ALL ( 'Table'[date], 'Table'[Product_id] ),
            'Table'[date] = MAX ( 'Table'[date] )
        ),
        [Measure]
    )
VAR _countofP =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Product_id] ),
        FILTER ( 'Table', 'Table'[date] = MAX ( 'Table'[date] ) )
    )
RETURN
    DIVIDE ( _sumofSales, _countofP, 0 )

Saludos

Rena

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

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors