Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
daniel_vale
Creator
Creator

Somar datas por período

Bom dia Comunidade!

Estou tentando fazer um set Analysis onde preciso a partir do meu campo DATA no calendário somar:

- Os valores desse mês - 03/2018

- Os valores do mês passado - 02/2018

- Os valores desse mês do ano passado - 03/2017

- Os valores do mês passado do ano passado - 02/2017

Podem me ajudar?

Labels (1)
11 Replies
Anil_Babu_Samineni

Perhaps this?

- Sum ({<Year = {$(=Max(Year)), Month = {$(=Max(Month))}}>} Sales)

- Sum ({<Year = {$(=Max(Year)), Month = {$(=AddMonths(Max(Month), - 1))}}>} Sales)

- Sum({<Year = {$(=Max(Year-1)), Month = {$(=Max(Month))}}}} Sales)

- Sum({<Year = {$(=Max(Year-1)), Month = {$(=Max(Month-1))}}}} Sales)

In fact, we have other ways to achieve this? Does this helps

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
daniel_vale
Creator
Creator
Author

Thanks for the help but it did not work.

Anil_Babu_Samineni

When you say it is not working, That means - Your field holding Year-Month format. I would suggest you to split into 2 fields which called Year and Month (Which are numbers) should work above conditions

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
daniel_vale
Creator
Creator
Author

Correct, the structure of my calendar looks like this:

Calendar:

Month(DataBase)          as Mês,

Year(DataBase)          as Ano

and making the expression the way it showed it was like this:

Thiago_Justen_

Como o loveisfail bem disse, seu campo data está com formato MM/YYYY. O que seria interessante é criar um novo campo em script para utiliza-lo no set analysis que o Anil Badu já te passou:

Date(Date#([Finish Date],'MM/YYYYY'),'DD/MM/YYYY') as NOVA_DATA


Isso facilitaria o set analysis...

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago
Thiago_Justen_

Daniel,

Use esse campo DataBase (que suponho estar formatado dd/mm/yyyy) no set analysis que o Anil te passou.

Se você "dropa" esse campo no script seria legal mante-lo para facilitar o set...

Podes fazer com ele algo como:

Date(Floor(DataBase)) as DataBase

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago
Anil_Babu_Samineni

May be try for first result expression?

Num(Month(DataBase)) as Mês,

Year(DataBase) as Ano

For Current one - Sum ({<Ano = {$(=Max(Ano)), Mês = {$(=Max(Mês))}}>} Sales)


Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
daniel_vale
Creator
Creator
Author

Ah sim, ele já está nesse formato com o floor.

Thiago_Justen_

Nesse caso:

- Os valores desse mês - 03/2018

Sum({<DataBase={">=$(=MonthStart(Max(DataBase)))"}>}SEU_VALOR)

- Os valores do mês passado - 02/2018

Sum({<DataBase={">=$(=MonthStart(AddMonths(Max(DataBase),-1)))<=$(=MonthEnd(AddMonths(Max(DataBase),-1)))"}>}SEU_VALOR)


- Os valores desse mês do ano passado - 03/2017

Sum({<DataBase={">=$(=AddYears(MonthStart(Max(DataBase)),-1))<=$(=AddYears(MonthEnd(Max(DataBase)),-1))"}>}SEU_VALOR)

- Os valores do mês passado do ano passado - 02/2017

Sum({<DataBase={">=$(=AddYears(MonthStart(AddMonths(Max(DataBase),-1)),-1))<=$(=AddYears(MonthEnd(AddMonths(Max(DataBase),-1)),-1))"}>}SEU_VALOR)

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago