Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Solved! Go to Solution.
Hi @homelander123
Welcome to the Microsoft Fabric Forum. Also, thank you @samratpbi for your quick response.
The issue with your DAX formula arises from how filter logic is applied within the CALCULATE function. Specifically, the expression:
Query1[CSMDate] >= LastYearSameMonthStart && Query1[CSMDate] <= LastYearSameMonthEnd
does not behave as intended within CALCULATE() unless it is wrapped in a FILTER() function. This is because CALCULATE expects a table expression for filtering, not just a Boolean condition.
While I may not have full visibility into the specific structure of your dataset, I have created a sample .pbix file to demonstrate one possible approach to implementing the desired logic.
Consider the below DAX:
CMLYNAACount =
VAR SelectedMonth = MAX(Query1[CSMDate])
VAR LastYearSameMonthStart = EOMONTH(SelectedMonth, -13) + 1
VAR LastYearSameMonthEnd = EOMONTH(SelectedMonth, -12)
RETURN
CALCULATE(
SUM(Query1[NACCount]),
FILTER(
ALL(Query1),
Query1[CSMDate] >= LastYearSameMonthStart &&
Query1[CSMDate] <= LastYearSameMonthEnd
)
)
I have included relevant screenshot and attached the .pbix file for your reference.Please take a moment to review them and see if this solution aligns with your requirements.
If this information helps resolve your issue, kindly consider marking this response as the Accepted Solution, as it may assist other community members facing similar challenges.
Thank you!
May I ask if you have resolved this 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.
Hi @homelander123
Welcome to the Microsoft Fabric Forum. Also, thank you @samratpbi for your quick response.
The issue with your DAX formula arises from how filter logic is applied within the CALCULATE function. Specifically, the expression:
Query1[CSMDate] >= LastYearSameMonthStart && Query1[CSMDate] <= LastYearSameMonthEnd
does not behave as intended within CALCULATE() unless it is wrapped in a FILTER() function. This is because CALCULATE expects a table expression for filtering, not just a Boolean condition.
While I may not have full visibility into the specific structure of your dataset, I have created a sample .pbix file to demonstrate one possible approach to implementing the desired logic.
Consider the below DAX:
CMLYNAACount =
VAR SelectedMonth = MAX(Query1[CSMDate])
VAR LastYearSameMonthStart = EOMONTH(SelectedMonth, -13) + 1
VAR LastYearSameMonthEnd = EOMONTH(SelectedMonth, -12)
RETURN
CALCULATE(
SUM(Query1[NACCount]),
FILTER(
ALL(Query1),
Query1[CSMDate] >= LastYearSameMonthStart &&
Query1[CSMDate] <= LastYearSameMonthEnd
)
)
I have included relevant screenshot and attached the .pbix file for your reference.Please take a moment to review them and see if this solution aligns with your requirements.
If this information helps resolve your issue, kindly consider marking this response as the Accepted Solution, as it may assist other community members facing similar challenges.
Thank you!
Hi,
though I am not sure about the data, however I think you need to make the below change:
VAR LastYearSameMonthStart = EOMONTH(SelectedMonth, -13) + 1
EOMONTH returns last date of the month. If you are doing -12 then + 1, besically its returning 1st day of the following month, which makes your month start date greater than month end date. I think that is the reason you are not getting any values.
If this helps to resolve your problme, then please mark it as solution, thanks - Samrat
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
24 | |
10 | |
6 | |
6 | |
6 |
User | Count |
---|---|
29 | |
11 | |
11 | |
10 | |
6 |