Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
hello community,
i have a meseare to calculate the sales quantity,
i need to calculate the average sales of last 3 months
eg; we are on january, i need the sum of last 3 months /3 (october, november and december)
and next months, it calculates (november, december and january)
i copied a measure from SQLBI, but it doesn't works as i want
Solved! Go to Solution.
That version is including the current month in the calculation, you want to exclude that so I think you just need to tweak the LastCurrentDate
Sales R3M =
VAR NumOfMonths = 3
VAR LastCurrentDate =
MIN ( 'Date'[Date] ) - 1
VAR Period =
DATESINPERIOD ( 'Date'[Date], LastCurrentDate, - NumOfMonths, MONTH )
VAR Result =
CALCULATE (
SUMX ( VALUES ( 'Date'[Month Year] ), [Sales Quantity] ) / 3,
Period
)
VAR FirstDateInPeriod =
MINX ( Period, 'Date'[Date] )
VAR LastDateWithSales =
MAX ( COM_DocumentDetail[CreationDate] )
RETURN
IF ( FirstDateInPeriod <= LastDateWithSales, Result )
Hi, @Sofinobi
You can try the following methods.
Measure:
Month Quantity = CALCULATE(SUM('Table'[Ouantity Now]),ALLEXCEPT('Date','Date'[Month]))Cumulative 3 month =
Var N1=SUMMARIZE(FILTER(ALL('Date'),[Month]<=SELECTEDVALUE('Date'[Month])),[Month],"Sum",[Month Quantity])
Var N2=TOPN(3,N1,[Month],DESC)
Return
SUMX(N2,[Sum])
Always calculate the sum of the last 3 months. Is this the result you expect?
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
thank you for your support, the answer from Johnt75 is exactely what i'm looking for.
thanks for you again
That version is including the current month in the calculation, you want to exclude that so I think you just need to tweak the LastCurrentDate
Sales R3M =
VAR NumOfMonths = 3
VAR LastCurrentDate =
MIN ( 'Date'[Date] ) - 1
VAR Period =
DATESINPERIOD ( 'Date'[Date], LastCurrentDate, - NumOfMonths, MONTH )
VAR Result =
CALCULATE (
SUMX ( VALUES ( 'Date'[Month Year] ), [Sales Quantity] ) / 3,
Period
)
VAR FirstDateInPeriod =
MINX ( Period, 'Date'[Date] )
VAR LastDateWithSales =
MAX ( COM_DocumentDetail[CreationDate] )
RETURN
IF ( FirstDateInPeriod <= LastDateWithSales, Result )
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 10 | |
| 10 | |
| 8 | |
| 6 | |
| 6 |
| User | Count |
|---|---|
| 24 | |
| 19 | |
| 19 | |
| 15 | |
| 9 |