Forum Discussion
devmcreif
3 years agoFrequent Visitor
Custom previous period data
Hello Power BI community,
I ran into a problem when trying to get the sales from different custom periods.
I created a new calendar table to get a union column with different period ranges (last 7 days, last 15 days, las 30 days, this month, last month and a personalized time period to select from a slicer.
I am trying to get the sales from the previous selected period, this is the DAX code I have:
Total Sales Last Period =
VAR startDayActPeriod =
FIRSTDATE(
'Calendario Rangos 2'[Date]
)
VAR EndDayActPeriod =
LASTDATE(
'Calendario Rangos 2'[Date]
)
VAR daysActPeriod =
DATEDIFF(
startDayActPeriod, EndDayActPeriod, DAY
)
VAR startDayLastPeriod =
FIRSTDATE(
DATEADD('Calendario Rangos 2'[Date], -1 * daysActPeriod, DAY))
VAR endDateLastPeriod =
PREVIOUSDAY(
LASTDATE(
DATEADD('Calendario Rangos 2'[Date], -1 * daysActPeriod, DAY)))
VAR result =
CALCULATE(
'Medidas KPI Sell out'[Total Ingresos],
DATESBETWEEN(
'Calendario Rangos 2'[Date],
startDayLastPeriod,
endDateLastPeriod
)
)
RETURN
result
This only works when I select a personalized period and choose a specific date from the date slicer.
However, when choosing a customized range, the result is "blank"
Thanks in advance for all your help!
No RepliesBe the first to reply