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

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.

Reply
Anonymous
Not applicable

Filtering a table similar to a where clause from SQL

Hi Community!

 

I am fairly new in DAX and I would like to ask for your help if there is way to convert this SQL query into DAX. I have 1 fact table in which I need to get the total amount of sales and 2 tables where this filters should be applied. is there a workaround with this query without the use of a date table?

 

SQL Query:

Period_ID between select period_ID from WeekTable where Week_ID =(select week_ID from DayTable where day_date =
(select DATEADD(Day, -120, CAST(GETDATE() AS DATE))))) and (select distinct period_ID from DayTable where day_date = CAST(GETDATE() AS DATE))

 

Here is the DAX that I have in mind, however, I'm encountering an error of "A function 'FILTER' has been used in a True/False expression that is used as a table filter expression. This is not allowed.". Are there a more appropriate DAX function to use in filtering, and should I use a calculated column or table, or this may be done with a single measure?

 

DAX:

2_test =
CALCULATE(
    SUM(SALES[Sales_Amount]),
        SALES[PERIOD_ID] = (FILTER(WeekTable, WeekTable[Week_ID] = FILTER(DayTable, DayTable[Day_date] = TODAY() - 120)
Looking forward for your suggestions. Thank you very much!
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , the sql code is not complete

 

if you data for last 120 days based on today

measure =

var _min = TODAY() -120
var _max = today()
return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

 

 

You need few week based on today

 

Weeks Today =
var _min = today() -WEEKDAY(today() ,2) +1 - 7*12 //12 weeks
var _max =today() -WEEKDAY(today() ,2) +7
return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

 

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

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

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , the sql code is not complete

 

if you data for last 120 days based on today

measure =

var _min = TODAY() -120
var _max = today()
return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

 

 

You need few week based on today

 

Weeks Today =
var _min = today() -WEEKDAY(today() ,2) +1 - 7*12 //12 weeks
var _max =today() -WEEKDAY(today() ,2) +7
return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

 

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.