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!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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 & @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]
)
@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
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 13 | |
| 5 | |
| 5 | |
| 3 | |
| 3 |
| User | Count |
|---|---|
| 25 | |
| 10 | |
| 10 | |
| 6 | |
| 6 |