Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hi all,
I need to calculate the Average Sales only for the period that Sales data exist (red line).
The measure I created though expands to all dates in my Date table (blue line).
How can I fix that using DAX?
I tried DATESBETWEEN as shown, with no success.
Try
Sales avg all dates =
VAR FirstSale =
CALCULATE ( MIN ( 'Sales'[Date] ), REMOVEFILTERS ( 'Dates' ) )
VAR FirstVisibleDate =
EOMONTH ( FirstSale, -1 ) + 1
VAR LastSale =
CALCULATE ( MAX ( 'Sales'[Date] ), REMOVEFILTERS ( 'Dates' ) )
VAR LastVisibleDate =
EOMONTH ( FirstSale, 0 )
VAR MinDate =
MIN ( 'Dates'[Date] )
VAR MaxDate =
MAX ( 'Dates'[Date] )
VAR Result =
IF (
MinDate >= FirstVisibleDate
&& MaxDate <= LastVisibleDate,
CALCULATE (
AVERAGEX ( VALUES ( 'Dates'[Month & Year] ), [Sales] ),
REMOVEFILTERS ( 'Dates' )
)
)
RETURN
Result
Thank you @johnt75 ,
Suggested measure works as far as calculation is concerned, but not as expected in visual.
Use Performance Analyzer to copy the query for the visual into DAX Studio. You can then use the Define Measure feature in DAX Studio to change the measure to return each of the intermediate variables in turn, that should identify which variable is being calculated incorrectly.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
18 | |
15 | |
11 | |
11 | |
8 |
User | Count |
---|---|
24 | |
18 | |
12 | |
11 | |
10 |