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
Shlomiaf7
New Member

How to calculate an amount in a column of invoices according to a column of months?

How can I calculate an amount in a certain column according to the month that is in the same row with it in the invoices table and it is linked to a table of dates, I want to calculate a total amount for each month separately throughout all the years (for example: January 2018-2023, February 2018-2023, etc.).
I need to average by month over the years.
Many thanks to the helpers.facr invoices tablefacr invoices tabledim date tabledim date table

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

Hi @Shlomiaf7 ,

Here are my test data snapshots. There are two tables.

vheqmsft_0-1700716442386.png

vheqmsft_1-1700716468633.png

vheqmsft_3-1700716493218.png

Then follow steps:

1.To achieve calculate total according to selected year and month range, create measure like below:

 

Total = 
var _years=ALLSELECTED('date'[Year]) 
var _months=ALLSELECTED('date'[Month])
RETURN CALCULATE(
    SUM('invoices'[Amount]),
    FILTER(
        'invoices',
        YEAR('invoices'[year_month]) in _years && MONTH('invoices'[year_month]) in _months
    )
)

 

2. To achieve calculate average according to selected year and month range, create measure like below:

 

Average = 
var _years=ALLSELECTED('date'[Year]) 
var _months=ALLSELECTED('date'[Month])
RETURN CALCULATE(
    AVERAGE('invoices'[Amount]),
    FILTER(
        'invoices',
        YEAR('invoices'[year_month]) in _years && MONTH('invoices'[year_month]) in _months
    )
)

 

3.Final output

vheqmsft_4-1700716262248.png

In order for you to solve the problem faster, you can refer to the following documentation.

How to Get Your Question Answered Quickly - Microsoft Fabric Community

 

Best regards,

Albert HE

 

View solution in original post

2 REPLIES 2
v-heq-msft
Community Support
Community Support

Hi @Shlomiaf7 ,

Here are my test data snapshots. There are two tables.

vheqmsft_0-1700716442386.png

vheqmsft_1-1700716468633.png

vheqmsft_3-1700716493218.png

Then follow steps:

1.To achieve calculate total according to selected year and month range, create measure like below:

 

Total = 
var _years=ALLSELECTED('date'[Year]) 
var _months=ALLSELECTED('date'[Month])
RETURN CALCULATE(
    SUM('invoices'[Amount]),
    FILTER(
        'invoices',
        YEAR('invoices'[year_month]) in _years && MONTH('invoices'[year_month]) in _months
    )
)

 

2. To achieve calculate average according to selected year and month range, create measure like below:

 

Average = 
var _years=ALLSELECTED('date'[Year]) 
var _months=ALLSELECTED('date'[Month])
RETURN CALCULATE(
    AVERAGE('invoices'[Amount]),
    FILTER(
        'invoices',
        YEAR('invoices'[year_month]) in _years && MONTH('invoices'[year_month]) in _months
    )
)

 

3.Final output

vheqmsft_4-1700716262248.png

In order for you to solve the problem faster, you can refer to the following documentation.

How to Get Your Question Answered Quickly - Microsoft Fabric Community

 

Best regards,

Albert HE

 

lbendlin
Super User
Super User

according to the month that is in the same row with it in the invoices table

not sure what you mean by that. What is the join column?

 

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
If you are unsure how to do that please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

If you want to get answers faster please refer to https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

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.