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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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