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: 
RafaelLucasdaCosta
Contributor II
Contributor II

Vendas no mesmo dia da semana no ano passado

Olá a todos. Eu tenho um gráfico de barras no meu projeto que é o cálculo das vendas a nível de dia, considerando o mês e ano selecionados. Eu consegui fazer o cálculo para as vendas no mesmo dia do ano passado. Porém preciso levar em consideração o dia da semana. Sendo assim, considerando que minha data atual seja 21/07/2021 (Quarta-Feira), eu preciso calcular o valor do ano passado no dia 22/07/2020, que seria a quarta feira do mês equivalente a do ano atual. Essa última informação pretendo exibir como um marcador no mesmo gráfico que tenho as vendas do ano atual. Eu já tenho uma Master Calendar no meu projeto com informações de Semana, Dia etc. Vi em alguns posts que é necessário criar uma outra tabela Auxiliar de Data, mas não entendi como poderia fazer isso e como eu calcularia esses dias específicos. Desde já agradeço!

2 Replies
JuanGerardo
Partner - Specialist
Partner - Specialist

Olá @RafaelLucasdaCosta, you can do it in different ways, for example creating an auxiliary equivalent date field and using it to filter the date, for example something like:

Sum({<MyDate = {$(Max(DateEquivalent))}>} Sales)

Where in your calendar table MyDate = 21/07/2021 and DateEquivalent = 22/07/2020 in the same row, generated with the logic you need.

 

But if your logic is based on the month week number, you can create the MonthWeekNumber field and use it in the following way:

Script:
CalendarTable:
Load ...
   Date(ReferenceDate) AS MyDate,
   WeekDay(ReferenceDate) AS WeekDay,
   Month(ReferenceDate) AS Month,
   Year(ReferenceDate) AS Year,
   Ceil(Day(ReferenceDate) / 7) AS MonthWeekNumber,
...

Chart expression:
Sum({<Year = {$(=Max(Year) - 1)}, Month = {$(=Max(Month))}, MonthWeekNumber = {$(=Max(MonthWeekNumber))}, WeekDay = {$(=Max(WeekDay))}>} Sales)

You can calculate the MonthWeekNumber with other logic, specially for weeks with days belonging to two months.

JG

RafaelLucasdaCosta
Contributor II
Contributor II
Author

Hi @JuanGerardo , thanks for answering.

I tested both options. By creating the equivalent date field in my master calendar table and using this SA 

Sum({<MyDate = {$(=Max(DateEquivalent))}>} Sales)

I get no results. I don't think it makes sense to compare MyDate with DateEquivalent in the way you suggested as they will always be different.
Creating the Month Week Number field and using this SA 

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

results in 0 in my chart. I'm new to Qlik Sense, so I might be really missing something. Any more Suggestions?