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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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