Forum Discussion

axeelcs's avatar
axeelcs
Regular Visitor
8 years ago

Last year value but without format date

Hi everyone, I am having this issue where I have to calculate the last year value, but I am not working with a format Date, because we are working with weeks.

 

I have a table like this, called View_BT_Comercial

 

 

 

In my page, I 've this filters wich I want to keep for the calculate of the last year:

 

 

So in one of my measures the DAX functions that i use to calculate the actual year and the last are :

ACTUAL : 

 

Ventas_Totales = SUMX(View_BT_Comercial,View_BT_Comercial[Precio_Unitario]*View_BT_Comercial[Unidades])

LAST YEAR :

 

ventas_totales_LY = CALCULATE(sumx(View_BT_Comercial,View_BT_Comercial[Precio_Unitario]*View_BT_Comercial[Unidades]),filter(all(View_BT_Comercial),View_BT_Comercial[anioretail] =max(View_BT_Comercial[anioretail_ant]) && View_BT_Comercial[MesRetail] =max(View_BT_Comercial[MesRetail]) && View_BT_Comercial[semanaRetail] <=max(View_BT_Comercial[semanaRetail]) && View_BT_Comercial[Sucursal_ID]<=max(View_BT_Comercial[Sucursal_ID] )))

So, I tried with just the calculated filters, but the equal "=" doesn't wok, then I tried with the function FILTER(ALL( ... like i posted, but when I dont select a month, or week, or sucursal,  it gives a wrong result, because of the "max" function ... so the next that i tried was FILTER(ALLEXCEPT( and put the columns sucursal, month and week, but nothing too .. I tried also with VALUES().

 

I really dont know what to use ... Like i said before, cause I am not working with a date format, i created a calculated column wich "anioretail-1" so i can get the last year, mainly because I cant use DATEADD.

 

I need to get the last year value for the same month, week and sucursal, are o aren't filtered values.

 

Thanks !!!

3 Replies

  • Vvelarde's avatar
    Vvelarde
    Community Champion

    axeelcs

     

    Hi, try with this:

     

     

    TotalVentasPY =
    CALCULATE (
        [TotalVentas],
        FILTER (
            ALL ( Table1 ),
            Table1[Año]
                = SELECTEDVALUE ( Table1[Año] ) - 1
                && Table1[Mes] = SELECTEDVALUE ( Table1[Mes] )
                && Table1[Semana] = SELECTEDVALUE ( Table1[Semana] )
                && Table1[Sucursal] = SELECTEDVALUE ( Table1[Sucursal] )
        )
    )

    Regards

     

    Victor

    Lima  - Peru

     

    • axeelcs's avatar
      axeelcs
      Regular Visitor

      Hi Victor, thanks for the reply, but it only works when I have all the filter selected, but when I dont have nothing filtered it doesnt show anything.

      • Vvelarde's avatar
        Vvelarde
        Community Champion

        axeelcs

         

        Try with:

         

        TotalVentasPY =
        CALCULATE (
            [TotalVentas],
            FILTER (
                ALLEXCEPT ( Table1; Table1[Mes], Table1[Semana]; Table1[Sucursal] ),
                Table1[Año]
                    = SELECTEDVALUE ( Table1[Año] ) - 1
            )
        )