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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
devendarkatteko
New Member

Need last 7 days total sales

Hi Everyone,

Hope everyone doing well, I need your help to get last 7 days total sales for every month, Thanks in advance.

 

I have a sales table in that have date column and also sales values everyday the values added to the table 
Here my Requirement is I need to get the sum of sales value for last 7 days sum of sales for every month.
In below snipshot I have two columns in that I need last 7 days for example in the january month last 7 days (31,30,29,28,27,26,25)
I need to find out these 7 days sum of sales, Could you please guide me how can I write DAX for this requirement.  

devendarkatteko_0-1683821448167.png

 

2 REPLIES 2
tamerj1
Super User
Super User

@devendarkatteko  & @Greg_Deckler 

I believe this problem requires a YearMonth column to group by. This can be either in the Sales table or in 'Date' dimension table. Not having this column in the model would greatly complicate the solution. You csn still SUMMARIZE by 'Table'[Date].[Year] and  'Table'[Date].[Month] but not sure if would work and I highly don't recommend it. 
The following assumes that the YearMonth column is created in the Sales table. If you have a date table then simply use the YearMonth column from the date table in the following code instead of 'Table'[YearMonth]

Last 7 Days =
SUMX (
SUMMARIZE (
'Table',
'Table'[YearMonth],
"@Amount", SUMX ( TOPN ( 7, 'Table', 'Table'[Date] ), 'Table'[Sales] )
),
[@Amont]
)

Greg_Deckler
Community Champion
Community Champion

@devendarkatteko Assuming you have Month in your visual try something like this:

Measure = 
  VAR __EndDate = MAX('Table'[Date])
  VAR __BeginDate = __EndDate - 7
  VAR __Table = FILTER(ALL('Table'), [Date] >= __BeginDate && [Date] <= __EndDate)
  VAR __Result = SUMX( __Table, [sales] )
RETURN
  __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.