Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe'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
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?
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 51 | |
| 37 | |
| 35 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 70 | |
| 65 | |
| 39 | |
| 33 | |
| 23 |