Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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.
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
13 | |
11 | |
9 | |
6 |