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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
agustira97
Frequent Visitor

Visualize Data During Last 1 Year (Example: 01 June 2021 until 31 May 2022)

I have monthly data that will be updated every first day of the month.
I have a case, to visualize data during 1 last year, for example when slicer year = 2022 and month = 5, it will take data from 01 June 2021 until 31 May 2022. How to make dax to provide this case?

I tried to make dax on my Visual Studio and it looks like this:
Last1Year :=
VAR Select_Month = MONTH(MAX(Test[postingdate]))
VAR Select_Year = YEAR(MAX(Test[postingdate]))
VAR StartDate = DATE(Select_Year - 1, Select_Month + 1, 1)
VAR EndDate = EOMONTH(StartDate, 11)
RETURN
CALCULATE(
ABS(SUM(Test[value])),
FILTER(
Test,
Test[value] >= StartDate &&
Test[value] <= EndDate
)
)

but unfortunately, the output visual on my pbix when we put slicer year = 2022 and month = 5, it will just take value on May 2022.
Can you help me to correct my dax? Thank you.

*Excel Link: https://docs.google.com/spreadsheets/d/1nOkOOtVMdu0SXG21W5PR9dsyN42OQ_la/edit?usp=sharing&ouid=10548...
*This data have a relationship with calculated table DIM_DATE, here's the dax for it:
DIM_DATE := ADDCOLUMNS(
CALENDAR(DATE(2018,1,1),EOMONTH(TODAY(),-1)),
"day", DAY([Date]),
"week", WEEKNUM([Date]),
"month", MONTH([Date]),
"monthname", FORMAT([Date],"mmm"),
"quarter", FORMAT([Date],"q"),
"quartername", "Q"&FORMAT([Date],"q"),
"year", YEAR([Date]),
"lastmonth", EOMONTH(TODAY(),-1)
)

2 REPLIES 2
Rupak_bi
Super User
Super User

Hope you are looking for below result. Your formula is correct. only you need to use selected value. Else you may use below formula.

 

new value =

calculate(SUM(Test[value]),

all(DIM_DATE),

DIM_DATE[Date]>=date(SELECTEDVALUE(DIM_DATE[Date].[Year])-1,SELECTEDVALUE(DIM_DATE[Date].[MonthNo])+1,1),
DIM_DATE[Date]<=max(DIM_DATE[Date]))

 

 

Rupak_bi_0-1699615014942.png

 



Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

Thank you for the solution, but what missing is, from your solution you are using 1 slicer, right now I using 2 different slicer Year and Month, so what if the case right that?
Hope you can also help me for this case...

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.