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
sagadgreat
Helper I
Helper I

Constant Average

I need to have an average remain constant for every month on a visual based on only the first 3 months of the year.  Example:

 

Month3 mo AvgNet Sales

Jan

100

100

Feb100100
Mar100100
Apr10058
May10054
June10056

 

The goal is to use this to calculate a difference between net sales vs. the 3 month average.  I have tried several solutions to no avail so now turning to the group who knows best!

 

Also, please keep in mind that there is underlying data that includes customer, so the 3 month average on a visual should change upon filtering cusotmers. 

 

Customer A:

 

Month3 mo AvgNet Sales
Jan20

20

Feb2020
Mar2020
Apr205
May2010
June2016

 

My dataset looks like this: 

Customer#MonthNet Sales
123Jan56
124Jan58
125Jan12
128Jan900

 

It is a pivot table that has been unpivoted and continues in this manner, duplicating itself back to customer# 123 when it reaches February, and then doing the same through December.  I have created a basic month selection table that converts the month to a date to attempt datesbetween (which of course only does the calculation on those 3 months and nothing else), etc.  Any help is appreciated.  

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @sagadgreat ,

 

My sample data is this.

Month

Net Sales

MonthNum

Customer

Year

Jan

100

1

A

2020

Feb

100

2

A

2020

Mar

100

3

A

2020

Apr

58

4

A

2020

May

54

5

A

2020

Jun

56

6

A

2020

Jan

50

1

B

2020

Mar

100

3

B

2020

Apr

54

4

B

2020

May

58

5

B

2020

Jun

56

6

B

2020

Jan

100

1

A

2019

Feb

50

2

A

2019

Mar

100

3

A

2019

Apr

58

4

A

2019

May

54

5

A

2019

Jun

56

6

A

2019

 

1.Create a measure to get the 3 month average.

3 mo ave = 
DIVIDE (
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Customer], 'Table'[Year] ),
            [Month] IN { "Jan", "Feb", "Mar" }
        )
    ),
    3
)

 

2.Create a measure to get the difference between net sales and the 3 month average.

difference = [3 mo ave]-MAX('Table'[Net Sales])

 

3.The result is as follows. Let the filter select a single select.

1.png2.png

 

 

You can check more details from here.

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Show the exact result that you are expecting.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-stephen-msft
Community Support
Community Support

Hi @sagadgreat ,

 

My sample data is this.

Month

Net Sales

MonthNum

Customer

Year

Jan

100

1

A

2020

Feb

100

2

A

2020

Mar

100

3

A

2020

Apr

58

4

A

2020

May

54

5

A

2020

Jun

56

6

A

2020

Jan

50

1

B

2020

Mar

100

3

B

2020

Apr

54

4

B

2020

May

58

5

B

2020

Jun

56

6

B

2020

Jan

100

1

A

2019

Feb

50

2

A

2019

Mar

100

3

A

2019

Apr

58

4

A

2019

May

54

5

A

2019

Jun

56

6

A

2019

 

1.Create a measure to get the 3 month average.

3 mo ave = 
DIVIDE (
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Customer], 'Table'[Year] ),
            [Month] IN { "Jan", "Feb", "Mar" }
        )
    ),
    3
)

 

2.Create a measure to get the difference between net sales and the 3 month average.

difference = [3 mo ave]-MAX('Table'[Net Sales])

 

3.The result is as follows. Let the filter select a single select.

1.png2.png

 

 

You can check more details from here.

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Apologies about getting back to this so late!!  Excellent solution. Thanks.

DataInsights
Super User
Super User

@sagadgreat, try this measure:

 

3 month average = 
VAR vYear =
    MAX ( 'Date'[Year] )
VAR vDates =
    FILTER (
        ALL ( 'Date' ),
        'Date'[Year] = vYear
            && 'Date'[Month Number] IN { 1, 2, 3 }
    )
VAR vResult =
    CALCULATE ( AVERAGE ( NetSales[Net Sales] ), vDates )
RETURN
    IF ( ISBLANK ( MAX ( NetSales[Net Sales] ) ), BLANK (), vResult )

 

You'll need a date table that's joined to the net sales table.

 

DataInsights_0-1599056714933.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.