Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Anonymous
Not applicable

DAX LAST7DAYS AVG

Hi,

 

Why do huge difference is coming between Last7d(22425822 etc) and Last7d avg(13.09 etc) values which has shown in below table.could any one please modify my dax.

 

Last7d =
CALCULATE (
SUMX(sales,sales[salesdetail.qty]),
DATESINPERIOD ( 'Calendar'[Date],LASTDATE ('Calendar'[Date]),-7,DAY )
)
 
Last7d avg =
CALCULATE (
AVERAGE (sales[salesdetail.qty]),
DATESINPERIOD ( 'Calendar'[Date],LASTDATE('Calendar'[Date]),-7,DAY )
)

  

Last7d        Last7d avg  Date
22425822     13.09     1-Aug-19
30914263     11.89     2-Aug-19
8642104       11.13     3-Aug-19
7504866       11.25    4-Aug-19
9374137       9.91      5-Aug-19
7521041       9.06       6-Aug-19
8354975       8.54       7-Aug-19
8453644       8.88       8-Aug-19
8137744       9.19       9-Aug-19
2 REPLIES 2
amitchandak
Super User
Super User

Have you check manually which one is correct. Check the Sum and Avg using this

Sales 10 Days = ( 
VAR _Cuur_start = Max('Compare Date'[Compare Date]) -7
VAR _Curr_END = Max('Compare Date'[Compare Date])
return 
calculate((sum(Sales[Sales Amount]),Sales[Sales Date] >= _Cuur_start && Sales[Sales Date] <=  _Curr_END )
)

 

JVidal
Helper I
Helper I

Hey, 

 

My guess is that you are using SUMX instead of SUM, so you are basically summing the entire sales table and then calculate what that is for the 7d.

 

Try changing SUMX by SUM

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.