The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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 !!!
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
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.
Try with:
TotalVentasPY = CALCULATE ( [TotalVentas], FILTER ( ALLEXCEPT ( Table1; Table1[Mes], Table1[Semana]; Table1[Sucursal] ), Table1[Año] = SELECTEDVALUE ( Table1[Año] ) - 1 ) )