Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!View all the Fabric Data Days sessions on demand. View schedule
In Power BI, I need a DAX measure to calculate sales, filtering, by default, the last 12 months, however, if there is an external filter in the calendar table, the sales value to be returned must respect the external filter, if there is no external filter in the calendar table then the value to return must be the sales corresponding to the last 12 months. In the calendar table there is a column that identifies the last 12 months where the month that is part of the last 12 months is marked as 1 and the other months as 0. The name of this column is "[Last 12 Months]".
The DAX measure below partially meets these requirements, however, when performing an external filter on the calendar table that is outside the range of the last 12 months, the value returned is zero and this needs to be corrected so that if there is an external filter on the calendar table, the value returned must match the applied filter.
DAX...
IF(
NOT ISFILTERED('dCalendar'),
CALCULATE(
[USD Sales],
ALL('dCalendar'), -- Added to remove existing filters in the "dCalendar" table
'dCalendar'[Last 12 Months] = 1
),
CALCULATE(
[USD Sales],
'dCalendar',
'dCalendar'[Last 12 Months] = 1
)
)
Solved! Go to Solution.
Hi, I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.
I hope the below can provide some ideas on how to create a solution for your semantic model.
expected result measure: =
VAR _nofilterdayscount =
CALCULATE ( COUNTROWS ( dCalendar ), REMOVEFILTERS () )
VAR _filterdayscount =
CALCULATE ( COUNTROWS ( dCalendar ), ALLSELECTED ( dCalendar ) )
VAR _qty =
SUM ( Sales[Quantity] )
VAR _qtylast12months =
CALCULATE ( SUM ( Sales[Quantity] ), dCalendar[Last 12 Months] = 1 )
RETURN
IF ( _nofilterdayscount = _filterdayscount, _qtylast12months, _qty )
Thank you very much!! This was exactly what i was looking for
Hi, I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.
I hope the below can provide some ideas on how to create a solution for your semantic model.
expected result measure: =
VAR _nofilterdayscount =
CALCULATE ( COUNTROWS ( dCalendar ), REMOVEFILTERS () )
VAR _filterdayscount =
CALCULATE ( COUNTROWS ( dCalendar ), ALLSELECTED ( dCalendar ) )
VAR _qty =
SUM ( Sales[Quantity] )
VAR _qtylast12months =
CALCULATE ( SUM ( Sales[Quantity] ), dCalendar[Last 12 Months] = 1 )
RETURN
IF ( _nofilterdayscount = _filterdayscount, _qtylast12months, _qty )
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 13 | |
| 9 | |
| 8 | |
| 5 | |
| 3 |
| User | Count |
|---|---|
| 28 | |
| 20 | |
| 19 | |
| 19 | |
| 12 |