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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. 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.

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.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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