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
Syndicate_Admin
Administrator
Administrator

error in formula dax

good afternoon, I have a design

mancemo_0-1654543865010.png

I capture the year and month of the slicer, I need to get a value for the same period of a year before, for which I make the following formula

mes_ant = DATEADD(Hoja1[my],-1,YEAR)
where I subtract a year to the selected value, until there well because I get the following values
mancemo_1-1654543944226.png

now I need to add the value of the column for that month I use this

total_mes_ant = calculate(SUM(Hoja1[Value]),FILTER(Hoja1,Hoja1[my]=[mes_ant]))
but with that formula it generates emptiness
mancemo_2-1654543986000.png

but in the table if there data

mancemo_3-1654544012257.png

what can be my mistake?

9 REPLIES 9
Syndicate_Admin
Administrator
Administrator

I currently only have one table as shown in the image

mancemo_0-1654696851970.png

what I want is from selecting a month

mancemo_1-1654696893316.png

get the value of the value column for a previous year and the previous month

You need to modify the filter context to include the full table, by using ALL() or similar.

hello, what a pity it is not very clear to me how to do it, you help me on the formula as serious that pity

total_mes_ant = calculate(SUM(Hoja1[Value]),FILTER(Hoja1,Hoja1[my]=[mes_ant]))

something like 

 

total_mes_ant = 
var mes_ant = EDATE(SELECTEDVALUE(Hoja1[my]),-12)
return calculate(SUM(Hoja1[Value]),ALLSELECTED(),Hoja1[my]=[mes_ant])

 

or

total_mes_ant = calculate(SUM(Hoja1[Value]),SAMEPERIODLASTYEAR(Hoja1[my]))

generates the following error

mancemo_0-1654705737697.png

too many brackets

 

total_mes_ant = 
var mes_ant = EDATE(SELECTEDVALUE(Hoja1[my]),-12)
return calculate(SUM(Hoja1[Value]),ALLSELECTED(),Hoja1[my]=mes_ant)

hello indeed the formula is fine, but the value is still blank

mancemo_0-1654716153084.png

lbendlin
Super User
Super User

- show your data model

- consider using SAMEPERIODLASTYEAR()

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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