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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
jemalosa
Frequent Visitor

Calculated column

Hello,

I have tried to create a calculated column so that in that table I get values of percentage variation with respect to the previous month. As it is an example table and as you can see the months may not be consecutive, any idea? I have tried with this DAX but it gives me blank values.

Fecha Producto Precio GAP GAP Price variation
01-dic-23 SQL Server Enterprise 2 Corepack -1801999,84
01-dic-23 SQL Server Standard 2 Corepack 0,00
01-dic-23 WS Datacenter 16 Corepack -696000,40
01-dic-23 WS Standard 16 Corepack 0,00
01-abr-24 SQL Server Enterprise 2 Corepack -452501,94
01-abr-24 SQL Server Standard 2 Corepack -236042,40
01-abr-24 WS Datacenter 16 Corepack -584652,75
01-abr-24 WS Standard 16 Corepack 105433,30

 

 

 

 

Calculate column:

Variacion_Precio_GAP_7 =
VAR FechaActual = MAX('Licencias WS / SQL'[Fecha])
VAR FechaAnterior = EDATE(FechaActual, -1)
VAR Productos = VALUES('Licencias WS / SQL'[Producto])
VAR PrecioGAPActual =
    SUMX(
        Productos,
        CALCULATE(
            SUM('Licencias WS / SQL'[Precio GAP]),
            'Licencias WS / SQL'[Fecha] = FechaActual,
            'Licencias WS / SQL'[Producto] = EARLIER('Licencias WS / SQL'[Producto])
        )
    )
VAR PrecioGAPAnterior =
    SUMX(
        Productos,
        CALCULATE(
            SUM('Licencias WS / SQL'[Precio GAP]),
            'Licencias WS / SQL'[Fecha] = FechaAnterior,
            'Licencias WS / SQL'[Producto] = EARLIER('Licencias WS / SQL'[Producto])
        )
    )
RETURN
    IF(ISBLANK(PrecioGAPAnterior), BLANK(), DIVIDE(PrecioGAPActual - PrecioGAPAnterior, PrecioGAPAnterior))
 
Regards

 

1 ACCEPTED SOLUTION

Hi again,

I have found the solution:

Variacion_Precio_GAP =

VAR ProductoActual = 'Licencias WS / SQL'[Producto]
VAR precioanterior =CALCULATE (
    MAX('Licencias WS / SQL'[Precio GAP]),PREVIOUSMONTH('Licencias WS / SQL'[Fecha]),
    FILTER (
        ALL('Licencias WS / SQL'),
        'Licencias WS / SQL'[Producto] = ProductoActual
    )
)
RETURN
DIVIDE ('Licencias WS / SQL'[Precio GAP]- precioanterior, precioanterior)
 
Regards

View solution in original post

5 REPLIES 5
v-jialongy-msft
Community Support
Community Support

Hi @jemalosa 

 

Can you provide us with a solution, so that others who are experiencing similar problems can also benefit from it.

 

 

Best Regards,

Jayleny

 

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

Hi again,

I have found the solution:

Variacion_Precio_GAP =

VAR ProductoActual = 'Licencias WS / SQL'[Producto]
VAR precioanterior =CALCULATE (
    MAX('Licencias WS / SQL'[Precio GAP]),PREVIOUSMONTH('Licencias WS / SQL'[Fecha]),
    FILTER (
        ALL('Licencias WS / SQL'),
        'Licencias WS / SQL'[Producto] = ProductoActual
    )
)
RETURN
DIVIDE ('Licencias WS / SQL'[Precio GAP]- precioanterior, precioanterior)
 
Regards

Hello Jaylenly,

 

any ideas?

 

I thought I had the solution but it doesn't give me the correct data, can you help me?

This is the formula I used:

Variacion_Precio_GAP =
VAR FechaActual = MAX('Licencias WS / SQL'[Fecha])
VAR PrecioGAPActual = 'Licencias WS / SQL'[Precio GAP]
VAR PrecioGAPAnterior =
    CALCULATE (
        MAX ( 'Licencias WS / SQL'[Precio GAP] ),
        FILTER (
            'Licencias WS / SQL',
            'Licencias WS / SQL'[Producto] = EARLIER ( 'Licencias WS / SQL'[Producto] )
                && 'Licencias WS / SQL'[Fecha] < FechaActual
        )
    )
RETURN
    IF (
        ISBLANK ( PrecioGAPAnterior ),
        BLANK (),
        DIVIDE ( PrecioGAPActual - PrecioGAPAnterior, PrecioGAPAnterior )
    )

 

I thought I had the solution but it doesn't give me the correct data, can you help me?

This is the formula I used:

Variacion_Precio_GAP =
VAR FechaActual = MAX('Licencias WS / SQL'[Fecha])
VAR PrecioGAPActual = 'Licencias WS / SQL'[Precio GAP]
VAR PrecioGAPAnterior =
    CALCULATE (
        MAX ( 'Licencias WS / SQL'[Precio GAP] ),
        FILTER (
            'Licencias WS / SQL',
            'Licencias WS / SQL'[Producto] = EARLIER ( 'Licencias WS / SQL'[Producto] )
                && 'Licencias WS / SQL'[Fecha] < FechaActual
        )
    )
RETURN
    IF (
        ISBLANK ( PrecioGAPAnterior ),
        BLANK (),
        DIVIDE ( PrecioGAPActual - PrecioGAPAnterior, PrecioGAPAnterior )
    )
jemalosa
Frequent Visitor

Resolved. Thank you

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.