Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
devmcreif
Frequent 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.
devmcreif_0-1691659351907.png

 

However, when choosing a customized range, the result is "blank"

devmcreif_1-1691659421301.png

 

Thanks in advance for all your help!

 

0 REPLIES 0

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.