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
Solved! Go to Solution.
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] )
)
)
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.
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] )
)
)
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.
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))
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?
Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!
User | Count |
---|---|
108 | |
75 | |
66 | |
50 | |
48 |
User | Count |
---|---|
164 | |
87 | |
77 | |
70 | |
67 |