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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
aghonaim
Most Valuable Professional
Most Valuable Professional

DAX Formula

Can someone help me with a simple formula to calcualte the value of the last year (which is YYYY number not a full date) ?

I tried the following formual but it isn't returning any values:

LY = Calculate(AVERAGE(Table[Value]), FILTER(ALL(Table), Table[YEAR] = Table[YEAR]-1))

1 ACCEPTED SOLUTION

Hi @aghonaim,

 

Sorry. Recreate it as a calculated column.

View solution in original post

8 REPLIES 8
AlbertoFerrari
Most Valuable Professional
Most Valuable Professional

The question is: "what do you want to see at the grand total"? Showing the value for 2012 looks a good compromise, but if you want to fix it, you first need to decide what to show there. At the grand total - being no year in the selection - the very value of "last year" is undefined.


Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

Alberto Ferrari - SQLBI
aghonaim
Most Valuable Professional
Most Valuable Professional

That's what I want to get which SivaMani solution allowed me to get it:

 

Capture.JPG

 

Makes sense ?

Is there a measure can do that ? if yes, which one is better/faster ?

mattbrice
Solution Sage
Solution Sage

Only thing i see your formula is missing to work is a MAX call:

 

LY = Calculate(AVERAGE(Table[Value]), FILTER(ALL(Table), Table[YEAR] = MAX ( Table[YEAR] ) -1 ) )

aghonaim
Most Valuable Professional
Most Valuable Professional

Thanks a lot! it worked but the LY total is not correct:

Capture.JPG

Can the totoal be fixed ?

@aghonaim,

 

The total is showing LY value of 2012. Because you have used MAX in your DAX. so, it picks Max(Year).

 

Just Create a calculated measure with following formula,

 

Last Year = LOOKUPVALUE(Table3[Value],Table3[Year],Table3[Year]-1) 

 

you will get the required Value.

 

Thanks,

Siva

aghonaim
Most Valuable Professional
Most Valuable Professional

I got this error:

A single value for column 'Year' in table 'Table' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

Hi @aghonaim,

 

Sorry. Recreate it as a calculated column.

aghonaim
Most Valuable Professional
Most Valuable Professional

Works fine now! Thanks a lot!

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.