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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
jd8766
Helper II
Helper II

Measure to show sales based on date selection vs the same period before?

Hello.

I have a Sales table and a measure that is a simple (Countrows[Sales]) to show me the number of sales within a certain period. I have a sold date table attached to this.

I want a measure that will dynamically calculate the sales variance based on the selected period... so if I select sold date between '01 nov 2022' and '3 nov 2022' this will show me sales for the '29th oct 2022' to '31st october 2022' as there are 3 days selected in my slicer, it will show the 3 days prior.

Another example, if I select '01 jan 2022' to '31 dec 2022' it will show me the sales for '01 jan 2021' and '31 dec 2021' as a full year is selected.

Is this possible? What would be the best way to achieve this in a measure?

Many thanks

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @jd8766 ,

 

Try formula like below:

Amount_filter = sum(FactInternetSales[SalesAmount])
To-Year = TOTALYTD([Amount_filter],M_DimDate[Date])
Last-To-Year = 
CALCULATE (
    [Amount_filter],
    DATESBETWEEN (
        M_DimDate[Date],
        NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( M_DimDate[Date] ) ) ),
        LASTDATE ( M_DimDate[Date] )
    )
)

 

vhenrykmstf_0-1668413413739.png

If the problem is still not resolved, please provide test data and expected result screenshoots. Looking forward to your reply.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

3 REPLIES 3
v-henryk-mstf
Community Support
Community Support

Hi @jd8766 ,

 

Try formula like below:

Amount_filter = sum(FactInternetSales[SalesAmount])
To-Year = TOTALYTD([Amount_filter],M_DimDate[Date])
Last-To-Year = 
CALCULATE (
    [Amount_filter],
    DATESBETWEEN (
        M_DimDate[Date],
        NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( M_DimDate[Date] ) ) ),
        LASTDATE ( M_DimDate[Date] )
    )
)

 

vhenrykmstf_0-1668413413739.png

If the problem is still not resolved, please provide test data and expected result screenshoots. Looking forward to your reply.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

DimaMD
Solution Sage
Solution Sage

Hi, @jd8766 try it

 

var min_date = Min('dates'[Date])
var min_date_LY = DATE(
    YEAR(
        MIN(
            'dates'[Date]))-1, 
            MONTH(min_date),
             DAY(min_date))
var max_date = Max('dates'[Date])
var max_date_LY = DATE(YEAR(MAX('dates'[Date]))-1, MONTH(max_date), DAY(max_date))
Return
CALCULATE([Sales], DATESBETWEEN('dates'[Date], min_date_LY, max_date_LY))

 


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

Hi, it doesn't work.. when I select date range '01 nov 2022' to '03 nov 2022' the minimum date this brings back is '01 nov 2021' when it should bring back '27 oct 2022'

as 3 days are selected in the slicer, the measure should look 3 days prior to the first date selected if that makes sense?

jd8766_0-1667486545725.png

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.