Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello community! I need your help.
I am working on a dashboard in Qlik Sense and I have a little problem. I need to calculate the variation between the current year and month (2020 / May) and the same year and month of last year (2019 / May).
Actually, I managed to do it annually with this sentence and creating two functions for the current year and the previous year (vAnoActual = max (year) and vAnoAnterior = vAnoActual -1):
= Num((SUM({<[Year]={'$(vAnoActual)'}>}Qty)/ SUM({<[Year]={'$(vAnoAnterior)'}>} Qty))-1,'#.##0%')
In the bar graph I used: = Num ((SUM (Qty) / above (SUM (Qty))) - 1, '#. ## 0%') and that works perfectly less when I want to see the current year and month current.
It is not analytically correct to compare a full year (12 months) vs. current year (5 months)
Also, when I change the dimension from years to months I have no problem using the ABOVE function. My problem is with the KPI, and when the dimension is YEAR (Imagen attached).
If you have any suggestions please let me know.
Thanks!!!
______________________
Hola comunidad! Necesito tu ayuda.
Estoy trabajando en un Dashboard de Qlik Sense y tengo un pequeño problema. Necesito calcular la variación entre el año y el mes actual (2020 / mayo) y el mismo año y mes del año pasado (2019 / mayo) para mostrarlo en un KPI.
En realidad, logré hacerlo anualmente con esta oración para la cual creé dos funciones para el año actual y el año anterior (vAnoActual = max (año) y vAnoAnterior = vAnoActual -1):
= Num ((SUM ({<[Año] = {'$ (vAnoActual)'}>} Cant) / SUM ({<[Año] = {'$ (vAnoAnterior)'}>} Cant)) - 1, ' #. ## 0% ')
En el gráfico de barras utilicé: = Num ((SUM (Cant) / above (SUM (Cant))) - 1, '#. ## 0%') y eso funciona perfecto menos cuando quiero ver el año actual y mes actual vs el año anterior y mismo mes que el actual.
Mi problema es que no es analíticamente correcto comparar un año completo (12 meses) con el año actual (5 meses)
Cuando cambio la dimensión de años a meses,no tengo problemas para usar la función ABOVE. Mi problema es con el KPI, y cuando la dimensión es AÑO (Imagen adjunta).
Sí tiene alguna sugerencia, por favor hazme saber.
¡¡¡Gracias!!!
One approach is to add the month filter in the Set Analysis.
Create a variable:
vMesActual = num(max({<[Year]={'$(vAnoActual)'}>} Month)) //variable to get the max month for current year
Then adjust your expression, adding a set analysis to filter the month:
Num((SUM({<[Year]={'$(vAnoActual)'}, Month={"<=$(vMesActual)"}>}Qty)/ SUM({<[Year]={'$(vAnoAnterior)'}, Month={"<=$(vMesActual)"}>} Qty))-1,'#.##0%')
One approach is to add the month filter in the Set Analysis.
Create a variable:
vMesActual = num(max({<[Year]={'$(vAnoActual)'}>} Month)) //variable to get the max month for current year
Then adjust your expression, adding a set analysis to filter the month:
Num((SUM({<[Year]={'$(vAnoActual)'}, Month={"<=$(vMesActual)"}>}Qty)/ SUM({<[Year]={'$(vAnoAnterior)'}, Month={"<=$(vMesActual)"}>} Qty))-1,'#.##0%')
Thank you so much @fosuzuki !!
That is working! I thought about it but didn't know how to do it ...
Now in the KPI it is perfect, but how do you use this in the bar chart when my dimension is Years (2016, 2017, 2018, 2019, 2020) if used the same sentence only can see the currently year vs the last year (imagen attached)
Before I used =Num((SUM(Qty)/above(SUM(Qty)))-1,'#.##0%')
Thanksss!
Best regards,
It is always good to create unique ids for period fields in script to perform point in time calculations.
This improves the performance, make code simple to understand and easy to maintain.
Try this:
=Num((SUM({<Month={"<=$(vMesActual)"}>}Qty)/above(SUM({<Month={"<=$(vMesActual)"}>}Qty)))-1,'#.##0%')