Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
3 years ago

Table comparing data from a specific period with the same period of the previous year

Good

I have a Sales table, with the units sold of a product. I have the years 2022 and 2023. The client can filter for a specific period of 2023. For example 25/01/2023 to 02/02/2023. As it appears in the filter:

Filtro fechaDate filter

I would like a table to appear with the month, day, you sold current year and you sold previous year.

The problem is that when I add the column UdsSoldPreviousPeriod, I get the following error:

It's like it won't let me calculate the units of the previous year by applying the filter segment of only the period 25/01/2023 - 02/02/2023. The measure I use to calculate the units of the previous year is as follows:

UdsVendidasPeriodoAnteriorNoWeb = 
var minfecha = MIN(Fecha[Fecha])
var minfechaN1 = DATE(YEAR(minfecha)-1,MONTH(minfecha),DAY(minfecha))
var maxfecha = MAX(Fecha[Fecha])
var maxfechaN1 = DATE(YEAR(maxfecha)-1,MONTH(maxfecha),DAY(maxfecha))
var calc = CALCULATE(SUM(Ventas[cantidad]), ALLCROSSFILTERED(Fecha), Ventas[fecha]>=minfechaN1 &&  Ventas[fecha]<=maxfechaN1)
return calc

How could I calculate it and show it in the table?

Thank you

2 Replies