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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Chelly
Frequent Visitor

Need Help with DAX Code - Date Filter Issue

Hi everyone,

I'm having trouble with DAX and I was hoping someone could help me out. My issue is that if there isn't a date filter, I want the DAX code to use the code date filter. However, if there is already a date filter in a table, matrix, or slicer, I want the measure to use that date filter instead.

I've tried using Chat GPT and other solutions, but unfortunately, they didn't work for me. If anyone has any ideas or suggestions, I would greatly appreciate it. Thanks in advance!

Currently, the filter is set to calculate the results for the current month -1, which works fine for January. However, users sometimes need to find data for different dates, and that's where the problem arises.

To make matters more complicated, I also have other measures that rely on the same principle.

Thanks

 

BS Periodic Amounts = ABS(CALCULATE(
 SUM('Fact'[Debit Amount])-SUM('Fact'[Credit Amount]),
    'Fact'[G_L Account No_] >= 100 &&
    'Fact'[G_L Account No_] <= 499 &&
 YEAR('Fact'[Posting Date]) = YEAR(TODAY()) &&
 MONTH('Fact'[Posting Date]) = MONTH(TODAY())-1
)
)

 

 

1 REPLY 1
amitchandak
Super User
Super User

@Chelly , Please Try the current/last month using time intelligence

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))

 

Time Intelligence, Part of learn Power BI https://youtu.be/cN8AO3_vmlY?t=27510
Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.