Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
How to get sales of Last Week, Last One Month, Last Three Month, Last Year sales based on selected weekending dates from slicer filter. By using DATESINPERIOD function I'm getting results for last week but when I'm using same function for last 1 Month, 3 Months, 6 Months & 1 Year it is giving me blank values. How to get values for this particular month.
This is how I'm doing my calculation.
Last Week % = DIVIDE(CALCULATE([MTV],DATESINPERIOD(DimDate[Date],SELECTEDVALUE(DimDate[WeekEndingDate]),-7,DAY)),[Old_Cost])
It is giving me results for last week but not for previous months which I wanted.
Note: In my slicer I'm using WeekEnding Dates which look like these 22/01/2023, 15/01/2023, 08/01/20223.
Any help would be greatly appreciated. Thank you.
@Ashish_Mathur
So if the date selected in 15/1/2023, then what period should be considered for "Last 1 month"? Also, share the download link of the PBI file.
For Last One Month 2022 December.
For 3 Months 2022 October
For 6 Months 2022 July
Here I'm attatching PBI file https://we.tl/t-j74qRll07w
This pattern should work for 1 prior month
P1_Month_1 =
VAR EFF_Price =
[OP] +
DIVIDE([CP],SUM(LData[TermPeriod])+[RP])
VAR Prior_Price =
[GP] +
DIVIDE([RP],SUM(LData[TermPeriod])+[Total_QC])
VAR Result = EFF_Price-Prior_Price
Return
DIVIDE(
CALCULATE(
Result,
datesbetween(DimDate[Date],eomonth(min(DimDate[WeekEndingDate]),-2)+1,eomonth(min(DimDate[WeekEndingDate]),-1))
),
Prior_Price
)
Getting same results for last one week & last one month
Check your data please. May be it is such that the result for previous week and previous month are the same.
Hey @Anonymous ,
I recommend reading this article, it contains almost everything regarding date/datetime calculations: Time patterns – DAX Patterns
Maybe you have to remove the existing filter context coming from the slicer selection if you are time-traveling backwards.
Wondering what the previous month will be, because a Calendar week can touch two months.
Please consider using the code sample tag in the future as DAX/M is more readable then:
Regards,
Tom
Last Week % = DIVIDE(CALCULATE([MTV],DATESINPERIOD(DimDate[Date],SELECTEDVALUE(DimDate[WeekEndingDate]),-7,DAY)),[Old_Cost])
This is the logic which I'm currently using it working for last week but not for Last 1,3,6 Months
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
106 | |
93 | |
75 | |
62 | |
50 |
User | Count |
---|---|
146 | |
109 | |
106 | |
88 | |
61 |