Forum Discussion
Dax Query Not working
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?
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!!
5 Replies
- Shravan133Super 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
)
) - v-sathmakuriCommunity 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!!
- v-sathmakuriCommunity 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-sathmakuriCommunity 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-sathmakuriCommunity 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!!