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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Narender
Resolver I
Resolver I

Last 2 year amount

Hi All,

 

I want a sum(amount) of last 2 year.Means sum(amount) group by last 2 year.

 

Like i want last 2 year sum.

 

 

 

Year   amount

 

2017   100$

2018   200$

-----------------

TOTAL  300$

 

Thanks

 

 

Narender

 

1 ACCEPTED SOLUTION

Hi Narender,

 

Try to use [Date] instead of [Enter_Date], please.

 

Best Regards,

Dale

Community Support Team _ Dale
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

19 REPLIES 19
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi Narender,

 

We can get the total in the "Total" row of the visual with the formula below. What's your issue?

Sales = sum('table'[Amount])

 

Best Regards,

Dale

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

Hi Dale, 

your expression will show the total amount. if i apply year in dimention in chart then it will show year wise amount.

 

I have year starting from 2000 to 2018 . So I want only last 2 year amount.

 

Means 2017 & 2018 amount only.

 

 

Year     Amount

2017    10$

2018    20$

Total    30$

 

 

So when 2019 will come then

It will show data for 2018 & 2019 only.

 

Thanks,

 

Narender

what about the DATESINPERIOD function?

 

last 2 years of sales =
CALCULATE([Total Sales],
    DATESINPERIOD('Date'[Date], MAX('Date'[Date]),-2,YEAR))

last2yearofsales.PNG

 

 

 

Hi,

 

As per your example , your are showing 4 year amount not 2 year.

 

If possible, Can you share a sample for this?

 

 

Thanks,

 

Narender

'the last 2 years' measure calculates value for 2 years.  for example, 2017 is the sum of 2016-2017

Yes Pawel , But I want it group by year.

 

2016 and 2017  seperatly amount in same table.

 

 

Thanks,

 

Narender

Actually i want last 2 year sum of amount group by last 2 year.

 

year     amount

2017   10$

2018    20$

Total     30$

 

 

Thanks,

 

Narender

 

Hi Narender,

 

Please check out the demo in the attachment.

Measure =
IF (
    HASONEFILTER ( 'Table'[Date].[Year] ),
    IF (
        YEAR ( MIN ( 'Table'[Date] ) )
            >= YEAR ( TODAY () ) - 1,
        SUM ( 'Table'[Value] ),
        BLANK ()
    ),
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( 'Table', YEAR ( 'Table'[Date] ) >= YEAR ( TODAY () ) - 1 )
    )
)

Last_2_year_amount

 

Best Regards,

Dale

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

Hi Dale,

it is showing me error in this line.

 

if(HASONEFILTER(TAX_TRANSACTION[ENTER_DATE].[Year])

 

.[Year] is not working with enter_date of tax_transactuion table.

 

Error: Column reference to 'ENTER_DATE' in table 'TAX_TRANSACTION' cannot be used with a variation 'Year' because it does not have any.

 

 

Please let me know how to resolve it.

 

Thanks,

 

Narender

 

Hi @Narender,

 

Can you share a dummy sample?

The cause could be that the column [ENTER_DATE] has a relationship with other table.

 

Best Regards,

Dale

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

Yes Dale,

 

Enter_date has a relationship with the date field of Calender.

 

Enter_Date  <--------------------  Date 

 

Let me know how to relove it?

 

Thanks,

 

Narender

 

Hi Narender,

 

Try to use [Date] instead of [Enter_Date], please.

 

Best Regards,

Dale

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

Thank you Dale . Its working now.  Smiley Happy

 

 

I need to add 1 more condition in it.

 

Last 2 year amount for the current month.

 

Example:

  Year                      Amount

 

 2017(June)              100$ (June2017 Amount)

 2018(June)              200$ (June2018 Amount)

 

 

Narender

Hi Narender,

 

It could be like below.

Measure =
IF (
    HASONEFILTER ( 'Table'[Date].[Year] ),
    IF (
        YEAR ( MIN ( 'Table'[Date] ) )
            >= YEAR ( TODAY () ) - 1,
        SUM ( 'Table'[Value] ),
        BLANK ()
    ),
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( 'Table', YEAR ( 'Table'[Date] ) >= YEAR ( TODAY () ) - 1 ),
        FILTER ( 'tax_payer', 'tax_payer'[FlAG] = "A" )
    )
)

Best Regards,

Dale

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

Thank you very much Dale. 

By mistake I have edited my last question and ask for new 1 condition.

 

Here I am writing again.

 

Again i am writing both new conditions.

 

1) Add a Filter in same condition (I got the idea from your last reply)

2) New question: add current month filter in DAX with same above condition.

 

Year          Amount

 

2018        100$                              // Amount of June 2018

2017        200$                               // Amount of June 2017

 

 

Thank You,

 

Narender

 

 

Hi Narender,

 

I would suggest you open a new thread in this forum to discuss the new topic which is different from this topic. Thanks for your understanding in advanced.

 

Best Regards,

Dale

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

Hi Dale,

 

As you suggested , i have created a new thread for the  "Last 2 year Collection for a particular month".

 

Can you assist me for that as previous one question was similar to this one.

 

I have created new thread with the name  "Last 2 year Collection for a particular month".

 

Thanks,

 

 

Narender

Ok  Dale. 

 

Thanks,

 

 

Narender

 

 

Greg_Deckler
Community Champion
Community Champion

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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