Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
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:
Solved! Go to Solution.
@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.
@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.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
8 | |
7 | |
6 |
User | Count |
---|---|
14 | |
13 | |
11 | |
9 | |
9 |