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
homelander123
Helper I
Helper I

Dax Query Not working

CMLYNAACount =
VAR SelectedMonth = MAX(Query1[CSMDate])
VAR LastYearSameMonthStart = EOMONTH(SelectedMonth, -12) + 1
VAR LastYearSameMonthEnd = EOMONTH(SelectedMonth, -12)

RETURN
CALCULATE(
    SUM(Query1[NACCount]),
    Query1[CSMDate] >= LastYearSameMonthStart && Query1[CSMDate] <= LastYearSameMonthEnd
)
I am trying to get a count based on a filter however, i am not getting any results on this query. Can you advise whats wrong?

1 ACCEPTED SOLUTION
v-sathmakuri
Community Support
Community Support

Hi @homelander123   , 

 

Thank you for reaching out to Microsoft Fabric Community.

 

Thank you @Shravan133   for the prompt response!! 

 

Create a datetable using the DAX code below.

 

DateTable =
ADDCOLUMNS (
    CALENDAR (DATE(2023, 1, 1), DATE(2025, 12, 31)),
    "Year", YEAR([Date]),
    "Month", FORMAT([Date], "MMMM"),
    "YearMonth", FORMAT([Date], "YYYY-MM")
)
 
Next, establish a relationship between both tables. The tables should be related based on the date and CSM date columns. Then, use the measure below to achieve the expected results. The PBIX file is also attached for reference.

 
CMLYNAACount =
VAR SelectedDate = MAX('DateTable'[Date])
VAR LastYearStart = DATE(YEAR(SelectedDate) - 1, MONTH(SelectedDate), 1)
VAR LastYearEnd = EOMONTH(LastYearStart, 0)
RETURN
CALCULATE(
    SUM(Query1[NACCount]),
    FILTER(
        ALL(Query1),
        Query1[CSMDate] >= LastYearStart &&
        Query1[CSMDate] <= LastYearEnd
    )
)
 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

 

Thank you!!

View solution in original post

5 REPLIES 5
v-sathmakuri
Community Support
Community Support

Hi @homelander123 ,

 

I hope the information provided is helpful. Feel free to reach out if you have any further questions or would like to discuss this in more detail. If responses provided answers your question, please accept it as a solution so other community members with similar problems can find a solution faster.

 

Thank you!!

v-sathmakuri
Community Support
Community Support

Hi @homelander123 ,

 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If the responses has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.

 

Thank you!!

v-sathmakuri
Community Support
Community Support

Hi @homelander123 ,

 

May I ask if the provided solution helped in resolving the issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

 

Thank you!!

v-sathmakuri
Community Support
Community Support

Hi @homelander123   , 

 

Thank you for reaching out to Microsoft Fabric Community.

 

Thank you @Shravan133   for the prompt response!! 

 

Create a datetable using the DAX code below.

 

DateTable =
ADDCOLUMNS (
    CALENDAR (DATE(2023, 1, 1), DATE(2025, 12, 31)),
    "Year", YEAR([Date]),
    "Month", FORMAT([Date], "MMMM"),
    "YearMonth", FORMAT([Date], "YYYY-MM")
)
 
Next, establish a relationship between both tables. The tables should be related based on the date and CSM date columns. Then, use the measure below to achieve the expected results. The PBIX file is also attached for reference.

 
CMLYNAACount =
VAR SelectedDate = MAX('DateTable'[Date])
VAR LastYearStart = DATE(YEAR(SelectedDate) - 1, MONTH(SelectedDate), 1)
VAR LastYearEnd = EOMONTH(LastYearStart, 0)
RETURN
CALCULATE(
    SUM(Query1[NACCount]),
    FILTER(
        ALL(Query1),
        Query1[CSMDate] >= LastYearStart &&
        Query1[CSMDate] <= LastYearEnd
    )
)
 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

 

Thank you!!

Shravan133
Super User
Super User

Try this:

CMLYNAACount =
VAR SelectedMonth = MAX(Query1[CSMDate])
VAR LastYearSameMonthStart = EOMONTH(SelectedMonth, -12) + 1
VAR LastYearSameMonthEnd = EOMONTH(SelectedMonth, -12)

RETURN
CALCULATE(
SUM(Query1[NACCount]),
FILTER(
ALL(Query1),
Query1[CSMDate] >= LastYearSameMonthStart &&
Query1[CSMDate] <= LastYearSameMonthEnd
)
)

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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