Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
devarshigoswami
Contributor II
Contributor II

Sum if month equal to and year equal to

Hi!

Thanks for taking the time to go through this. 

I need to show the sum of a measure in a histogram and KPI,  but only for a certain month-year. (current month year) 

to show the date in a month-year format here is the expression I used :


=date(MonthStart(date(DateField,'DD/MM/YYYY')),'MMM-YYYY')

now showing the measure in tabular format looks like this: 

Screenshot 2022-06-20 at 5.29.44 PM.png

 I only want to show the value for Jun-2022 in my visualization.so I tried this for the KPI:

 

=Sum({< MonthYear_debitdate={"Jun-2022"} >} amount_collected)

No errors are thrown but Im getting the total of the measure across all dimension, ie 18258014315 as the value

Screenshot 2022-06-20 at 5.34.19 PM.png

 

What Have I done wrong? how do I fix this? 

 

 

Labels (3)
1 Solution

Accepted Solutions
vinieme12
Champion III
Champion III

the format for MonthYear_debitdate is incorrect

You need to use the actual format of this field as it exist in the data model

Refer this article

https://community.qlik.com/t5/Qlik-Design-Blog/Dates-in-Set-Analysis/ba-p/1472511

 

alternatively you can also use below for calculations

=Sum({<debit_date={">=$(=Date(Monthstart(Max(debit_date))))<=$(=Date(Max(debit_date)))"} >} amount_collected)

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

3 Replies
luiferva
Contributor III
Contributor III

Hola Devarshigoswami 

Podrias poner tu metrica en el script y filtrar el periodo que necesitas con un where luego sumas y te quedaria un valor estatico con solo el periodo que necesitas.

Hize el siguiente script en el editor de codigo 

T:
	Load *
	Where Periodo = Date(Today(),'MMM-YYYY');
		
	LOAD * INLINE [
    Venta, #Mes, Año, Mes, Periodo
    50000, 1, 2022, Ene, ene-2022
    45566, 2, 2022, Feb, feb-2022
    34354, 3, 2022, Mar, mar-2022
    32323, 4, 2022, Abr, abr-2022
    67888, 5, 2022, May, may-2022
    43322, 6, 2022, Jun, jun-2022
    46462, 7, 2022, Jul, jul-2022
    323232, 6, 2022, Jun, jun-2022
    5654343, 5, 2022, May, may-2022
    2224343, 6, 2022, Jun, jun-2022
    343556, 6, 2022, Jun, jun-2022
    2543547, 6, 2022, Jun, jun-2022
];
 

Resultado

luiferva_0-1655786335552.png

Espero haber ayudado.

 

 

vinieme12
Champion III
Champion III

the format for MonthYear_debitdate is incorrect

You need to use the actual format of this field as it exist in the data model

Refer this article

https://community.qlik.com/t5/Qlik-Design-Blog/Dates-in-Set-Analysis/ba-p/1472511

 

alternatively you can also use below for calculations

=Sum({<debit_date={">=$(=Date(Monthstart(Max(debit_date))))<=$(=Date(Max(debit_date)))"} >} amount_collected)

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
luiferva
Contributor III
Contributor III

Hola Devarshigoswami 

Otra opción que vi hace poco que funciona es usar las funciones GetFieldSelections y GetPossibleCount

Paso 1

Crea una variable con la metrica

luiferva_0-1656547812135.png

esto obtendra los datos del periodo que el usuario seleccione

paso 2 

Crear una tabla o kpi con la expresion

IF(GetPossibleCount(periodo)=1,money(sum({<periodo={$(t)}>}Venta)),'Selecciona un periodo')

aca le estamos diciendo que si el usuario selecciona un registro del campo period, entonces sumas las ventas donde el periodo sea igual al valor que selecciono el usuario y si hizo mas de 1 filtro mostrara un texto

Resultado

luiferva_1-1656548085920.png

luiferva_2-1656548178827.png