How can I showcase a customers journey over time by sales grouping
eg Sales groupings
< 500
< 2000
<4000
<8000
8000
Customer A
first 11mths spend less than 500 on average therefore sits in group <500
in mth 12 they spend 5000 bringin the average to say £1249 therefore moving them to group <2000
The average would be calculated on a rolling 6mths
Please use this measure and let me know if it helps you for your scenario
You can apply in Matrix, table or visual of your choice
Sales R6Months =
VAR NumOfMonths = 6
VAR LastCurrentDate =
MAX ( Dates[Date] )
VAR Period =
DATESINPERIOD ( Dates[Date], LastCurrentDate, - NumOfMonths, MONTH )
VAR Result =
CALCULATE (
AVERAGEX (
VALUES ( Dates[MonthnYear] ),
[Total Sales]
),
Period
)
VAR FirstDateInPeriod = MINX ( Period, Dates[Date])
VAR LastDateWithSales = MAX ( Dates[Date])
RETURN
IF ( FirstDateInPeriod <= LastDateWithSales, Result )
Thank you Dhrubojit for your help - I think I’m getting there in my understanding. I have some questions about the variables
When I put this in a table it calculates the Sales R6Months up to Dec 21 even though there is no data past Sept 2021 - it looks like it calculates the average based on the number of months so not always 6mths
Is there a reason why the SalesData[SalesDate] column isn’t used in these variables and why isn’t MAXX used for the LastDateWithSales?
VAR LastCurrentDate = MAX ( Dates[Date])
VAR FirstDateInPeriod = MINX ( Period, Dates[Date])
VAR LastDateWithSales = MAX ( Dates[Date])
Thanks again for helping to further my understanding
Can you explain what the LastDateWithSales var is doing please - I know it getting the last date but why is it using the Dates table and not the Period table as in the FirstDateInPeriod variable
@AliB I have initially written it to not display average when date > sales date which in the initial query didn’t worked as you noted as corner scenario . .
Now with the optimized code , you don’t need those variables . .
You can remove them . . you can use the below measure which is more clean . .
Please check for yourself and let me know your feedback
Sales R6Months_updated =
VAR NumOfMonths = 6
VAR LastCurrentDate =
LASTNONBLANK ( Dates[Date], [Total Sales] )
VAR Period =
DATESINPERIOD ( Dates[Date], LastCurrentDate, - NumOfMonths, MONTH )
VAR Result =
CALCULATE ( AVERAGEX ( VALUES ( Dates[MonthnYear] ), [Total Sales] ), Period )
RETURN
Result
AS YOU See in the screen shot below -both mesure (with or without those vars return same result)
If your requirement is met with above approach , May I request to mark this as a Solution as a token of appreciation for the contribution effort and time (I do accept Love as well as well )
I can surely talk about alterntive solution in another thread as there are always so many(multiple) but finite possible options and alternative solutions to approach same problem
You would certainly get same results with multiple solution approach to exact same problem
@AliB I am trying to answer your next question; that you posted in same thread.
I don’t want to conflate the same theread the , the next question although related ; but is a different ask then the initial question on this thread
@AliB
Can you post a New form therad (question) -on your related question that you are Seeking help .
Please attach your pbix file with the measure you are saying is not working . .
For example you mentioned that why measure with calculate is not working , Can you pls give the full measure , PBIX to that I can access precisely ?