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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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