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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
jercks00
Regular Visitor

Average base on the range of month

Hello is this possible to do in power Bi.

I have the sum of sales per seller in a month from  July 2023 to July 2024.

What I want in my matrix table is the sum of Sales per Month and also show the Average sales from July 2023 to June 2024 Just like what I did in Excel

Untitled.jpg

 

 



 

 

 

2 ACCEPTED SOLUTIONS
Joe_Barry
Super User
Super User

Hi @jercks00 

 

Presuming that you have a calendar table in your model, this measure will show you the last 12 months, you can adapt it to other months too.

Sales R3M =
VAR NumOfMonths = 12
VAR LastCurrentDate =
    MAX ( 'Calendar'[Date] )
VAR Period =
    DATESINPERIOD ( 'Calendar'[Date], LastCurrentDate, - NumOfMonths, MONTH )
VAR Result =
    CALCULATE (
        AVERAGEX (
            VALUES ( 'Calendar'[Date] ),
            [Total Sales]
        ),
        Period
    )
VAR FirstDateInPeriod = MINX ( Period, 'Calendar'[Date] )
VAR LastDateWithSales = MAX ( Sales[Order Date] ) ///Enter the date that you want to calculate on
RETURN
    IF ( FirstDateInPeriod <= LastDateWithSales, Result )

 Hope this helps
Joe




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

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn
Let's connect on LinkedIn


View solution in original post

Anonymous
Not applicable

Hi @jercks00 

 

Thank you very much Joe_Barry for your prompt reply.

 

Tables in power BI are presented differently than excel, and you can't present them like excel.

 

Here I will offer some other ideas to help you solve the problem.

 

You need a data table, and a copy table. And establish a relationship between the two tables.

 

Here's some dummy data

 

“Table”

vnuocmsft_1-1724828544076.png

 

“copy Table”

vnuocmsft_2-1724828568813.png

 

pivot the Month and amount columns in the copy table in the power query.

 

vnuocmsft_3-1724828674894.png

 

vnuocmsft_4-1724828766606.png

 

Create a relationship between two tables in the Power BI Desktop.

 

vnuocmsft_5-1724828844133.png

 

Create measures.

 

Total = 
CALCULATE(
    SUM('Table'[Amount]),
    FILTER(
        ALL('Table'),
        'Table'[Name] = MAX('Table'[Name])
    )
)

 

Average = 
CALCULATE(
    AVERAGE('Table'[Amount]),
    FILTER(
        ALL('Table'),
        'Table'[Name] = MAX('Table'[Name])
    )
)

 

Create a table visual. And here is the result.

 

vnuocmsft_6-1724828950806.png

 

Regards,

Nono Chen

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

2 REPLIES 2
Anonymous
Not applicable

Hi @jercks00 

 

Thank you very much Joe_Barry for your prompt reply.

 

Tables in power BI are presented differently than excel, and you can't present them like excel.

 

Here I will offer some other ideas to help you solve the problem.

 

You need a data table, and a copy table. And establish a relationship between the two tables.

 

Here's some dummy data

 

“Table”

vnuocmsft_1-1724828544076.png

 

“copy Table”

vnuocmsft_2-1724828568813.png

 

pivot the Month and amount columns in the copy table in the power query.

 

vnuocmsft_3-1724828674894.png

 

vnuocmsft_4-1724828766606.png

 

Create a relationship between two tables in the Power BI Desktop.

 

vnuocmsft_5-1724828844133.png

 

Create measures.

 

Total = 
CALCULATE(
    SUM('Table'[Amount]),
    FILTER(
        ALL('Table'),
        'Table'[Name] = MAX('Table'[Name])
    )
)

 

Average = 
CALCULATE(
    AVERAGE('Table'[Amount]),
    FILTER(
        ALL('Table'),
        'Table'[Name] = MAX('Table'[Name])
    )
)

 

Create a table visual. And here is the result.

 

vnuocmsft_6-1724828950806.png

 

Regards,

Nono Chen

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

 

 

Joe_Barry
Super User
Super User

Hi @jercks00 

 

Presuming that you have a calendar table in your model, this measure will show you the last 12 months, you can adapt it to other months too.

Sales R3M =
VAR NumOfMonths = 12
VAR LastCurrentDate =
    MAX ( 'Calendar'[Date] )
VAR Period =
    DATESINPERIOD ( 'Calendar'[Date], LastCurrentDate, - NumOfMonths, MONTH )
VAR Result =
    CALCULATE (
        AVERAGEX (
            VALUES ( 'Calendar'[Date] ),
            [Total Sales]
        ),
        Period
    )
VAR FirstDateInPeriod = MINX ( Period, 'Calendar'[Date] )
VAR LastDateWithSales = MAX ( Sales[Order Date] ) ///Enter the date that you want to calculate on
RETURN
    IF ( FirstDateInPeriod <= LastDateWithSales, Result )

 Hope this helps
Joe




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

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn
Let's connect on LinkedIn


Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.