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

Don'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.

Reply
mrclay82
Helper II
Helper II

Average of future sales

Hi,

 

I have a measure called [future sales] which shows the forecasted sales per week.

 

I would like to calculate the average of this measure for the next 3 weeks and group the result by week.

 

 

So if the table is as below (pretending the week number is currently 30), the outcome should be 17,66 for week 30 (20+15+18)/3:

 

Week 30, future sales = 10

Week 31, future sales = 20

Week 32, future sales = 15

Week 33, future sales = 18

Week 34, future sales = 12

 

Figures in red are the desired outcome:

 

mrclay82_2-1702646539532.png

 

 

Thanks!

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@mrclay82 

Average Future Sales Next 3 Weeks =
VAR currentweek =
    SELECTEDVALUE ( yourtable[week] )
RETURN
    CALCULATE (
        AVERAGEX ( VALUES ( 'YourTable'[Week] ), [salesmeasure] ),
        yourtable[week] > currentweek,
        yourtable[week] <= currentweek + 3
    )
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

10 REPLIES 10
Dangar332
Super User
Super User

HI, @mrclay82 

 

try below

measure =
var currentweek = max(tablename[week])
return
averagex(
    filter(
        all(tablename[week]),
        tablename[week]> currentweek &&
        tablename[week] <= tablename[week]+3
     )
)

Hi,

Haven't tried yet but shouldn't my future sales measure be included there?

Hi, @mrclay82 

try updated code i am forgot to write [measure]

 

measure =
var currentweek = max(tablename[week])
return
averagex(
    filter(
        all(tablename[week]),
        tablename[week]> currentweek &&
        tablename[week] <= tablename[week]+3
     ),
[salesmeasure]
)

@Dangar332 

This measure overrides the date filters showing me earlier dates (historical dates) instead of future dates. My salesmeasure is a sum of a future sales column, only containing future values. But your measure breaks this showing only historical values with the same output all across.

Fowmy
Super User
Super User

@mrclay82 

Average Future Sales Next 3 Weeks =
VAR currentweek =
    SELECTEDVALUE ( yourtable[week] )
RETURN
    CALCULATE (
        AVERAGEX ( VALUES ( 'YourTable'[Week] ), [salesmeasure] ),
        yourtable[week] > currentweek,
        yourtable[week] <= currentweek + 3
    )
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Actually this worked after applying a date filter on the page! Many thanks!

Thanks @Fowmy !

It doesn't work all the way, probably due to insufficient info from my part.

What happens is that it is totally overriding my date filters and showing me earlier dates (historical dates) instead of future dates. 

I have a page filter that filters the page with a calculated column called 'forecasttable'[thisweek] which I have checked "Y" to only give me the future sales which is imported for this week.

I tried to modify your measure like this:

Average Future Sales Next 3 Weeks =

VAR currentweek =

    SELECTEDVALUE ( yourtable[week] )

RETURN

    CALCULATE (

        AVERAGEX ( VALUES ( 'YourTable'[Week] ), [salesmeasure] ),

        yourtable[week] > currentweek,

        yourtable[week] <= currentweek + 3,
        KEEPFILTERS(‘forecasttable’)           

    )

This gives me the correct dates (only showing the future, but the measure output is blank.

When modifying the measure like this:

Average Future Sales Next 3 Weeks =

VAR currentweek =

    SELECTEDVALUE ( yourtable[week] )

RETURN

    CALCULATE (

        AVERAGEX ( VALUES ( 'YourTable'[Week] ), [salesmeasure] ),

        yourtable[week] > currentweek,

        yourtable[week] <= currentweek + 3,
        KEEPFILTERS(‘forecasttable’[thisweek])           

    )

I get the following error: "Cannot convert value 'N' of type Text to type True/False".

Do you know the approach here? Please let me know if you need additional info.

Many thanks!

@mrclay82 

Sharing a dummy Power BI file representing your scenario would be beneficial. You can save the Power BI file on Google Drive or any other cloud storage platform and provide the link here. Kindly ensure that permission is granted to open the file.

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Is there another way? More info from my part? It is a fairy complex data model to replicate. 

@mrclay82 

Can you share some sample data with the desired output to have a clear understanding of your question?
You can either paste your data in the reply box or save it in OneDrive, Google Drive, or any other cloud-sharing platform and share the link here.

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.