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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Anonymous
Not applicable

Calculating the moving average of previous 4 weeks sales compared to last week sales

I have really problem about this:( I hope u can help me about this topic.

Thank u before your answers.

 

Today=X

 

I want to solve this porblem with dax.

My data occured 

Sales date, Amount and Product type. Each data correleated with each other.

 

Aim: Weekly moving average of total weekly sales by day, compared to the total of last 4 week sales

X to X-6 total sales amount / (X-7 to X-34)

 

1 ACCEPTED SOLUTION

so you don't want to compare the last seven days to the 28 days before that, but rather to their average.  In that case just multiply by 4.

 

 

measure =
var today=max([date])
var lastseven = calculate(sum([Sales]),[date]>today-7)
var lastthirtyfive = calculate(sum([Sales]),[date]>today-35)
return divide (4*lastseven,lastthirtyfive-lastseven)

 

I also see that you have created all separate measures. Please don't do that. The above code has to go into the definition of your single measure. The variables are part of the measure definition.

 

View solution in original post

6 REPLIES 6
lbendlin
Super User
Super User

Use variables to break the problem down

 

measure =

var today=max([date])

var lastseven = calculate(sum([Sales]),[date]>today-7)

var lastthirtyfive = calculate(sum([Sales]),[date]>today-35)

return divide (lastseven,lastthirtyfive-lastseven)

 

Adjust the column names as needed.

Anonymous
Not applicable

Hi again,

 

I am grateful for your help.

 

I wıll send my page because ı am not solve this problem. It ıs so complicated now:(.  I hope u can help me.

 

My aım: 

If today 25.06.2020, (sum of total sales of 25.06.2020 to 19.06.2020) / ((sum of total sales 18.06.2020 to 22.05.2020) /4)

 

A = sum of total sales of 25.06.2020 to 19.06.2020

B = (sum of total sales 18.06.2020 to 22.05.2020)1111.PNG3333.PNG

 

A/(B/4)

so you don't want to compare the last seven days to the 28 days before that, but rather to their average.  In that case just multiply by 4.

 

 

measure =
var today=max([date])
var lastseven = calculate(sum([Sales]),[date]>today-7)
var lastthirtyfive = calculate(sum([Sales]),[date]>today-35)
return divide (4*lastseven,lastthirtyfive-lastseven)

 

I also see that you have created all separate measures. Please don't do that. The above code has to go into the definition of your single measure. The variables are part of the measure definition.

 

Anonymous
Not applicable

I thınk smt is wrong on my page,

Maybe my problem is related in [Date]?

 
On the chart I want to see:

For example: Based on the 14th of May, the ratio of 4 * (8-14th of May total sales) to the sales of 7th May - 16th April. Likewise, I want to see the rate of 13 May. Like all the days of the moon

 

5555.PNG

Don't use a date hierarchy in your facts table - use your Dates table for that. The facts table should have just the raw date field.

 

In Options and settings, under Current File.. Data load  disable the "Auto Date/Time Hierarchy"

Anonymous
Not applicable

Spoiler
 
Perakende Karşılaştırmalı = 
(IF(
    ISFILTERED('Sayfa1'[Date]),
   
        AVERAGEX(
            DATESBETWEEN(
                'Sayfa1'[Date],
                (TODAY()-6),
                (TODAY())
            ),
            CALCULATE(SUM('Sayfa1'[Sales]))
        )
)
)/  
IF(
    ISFILTERED('Sayfa1'[Date]),

        SUMX(
            DATESBETWEEN(
                'Sayfa1'[Date],
                (TODAY()-34),
                (TODAY()-7)
            ),
            CALCULATE(SUM('Sayfa1'[Sales]))
        )/4
)

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.