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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
homelander123
Helper I
Helper I

Dax Query Not working

CurrentMonthLastYearCount = VAR SelectedMonth = MAX(Query1[SetupDate]) VAR LastYearSameMonthStart = EOMONTH(SelectedMonth, -12) + 1 VAR LastYearSameMonthEnd = EOMONTH(SelectedMonth, -12) RETURN CALCULATE( SUM(Query1[NewCount]), Query1[SetupDate] >= LastYearSameMonthStart && Query1[SetupDate] <= LastYearSameMonthEnd )

 

 

I am trying to write a query which shows current month last year in my matrix based on slicer date selection but this query wont return any reuslts and would show up as blank

 

 

1 ACCEPTED SOLUTION

@homelander123 If I understand what you are saying, you could do something like this and put it in a Card visual:

Measure = 
  VAR SelectedMonth = MAX(Query1[SetupDate]) 
  VAR LastYearSameMonthEnd = EOMONTH(SelectedMonth, -12) 
  VAR Result = FORMAT( LastYearSameMonthEnd, "mmm yyyy" )
RETURN
  Result


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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@homelander123 I think you want this:

CurrentMonthLastYearCount = 
  VAR SelectedMonth = MAX(Query1[SetupDate]) 
  VAR LastYearSameMonthStart = EOMONTH(SelectedMonth, -13) + 1 
  VAR LastYearSameMonthEnd = EOMONTH(SelectedMonth, -12) 
  VAR Result = CALCULATE( SUM(Query1[NewCount]), Query1[SetupDate] >= LastYearSameMonthStart && Query1[SetupDate] <= LastYearSameMonthEnd )
RETURN
  Result


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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

This works. Thank you so much. Can you please tell me how can i make the name dynamic to the slicer. E.g, if i have selected feb 2025 it should show feb 2024

@homelander123 If I understand what you are saying, you could do something like this and put it in a Card visual:

Measure = 
  VAR SelectedMonth = MAX(Query1[SetupDate]) 
  VAR LastYearSameMonthEnd = EOMONTH(SelectedMonth, -12) 
  VAR Result = FORMAT( LastYearSameMonthEnd, "mmm yyyy" )
RETURN
  Result


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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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