The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi,
If I want to return true if a person has won a has within 6 months of their whole time working at a job, how would I code this in Dax?
So for example, if User A has won a prize on 04/07/2020 and another prize on 05/10/2020 and worked at the company from 01/01/2020 (Start date) to 15/12/2020 (End date), how would I set a date filter to find if the user has won two prizes within 6 months of their start date and end date?
User | Prize Date | Start Date | End Date | Prize |
A | 04/07/2020 | 01/01/2020 | 15/12/2020 | 1 |
A | 05/10/2020 | 01/01/2020 | 15/12/2020 | 1 |
This is the example table. The Prize Count should show 1 after adding a measure using dax as User A has won two prizes in 6 months.
This is what I have so far:
(Users is the Table Name)
Hi @Anonymous ,
15/12/2020 is definitely December 15th, so 04/07/2020 and 05/10/2020 are July 4th and October 5th, right?
If it is, it does not meet the condition you said to be awarded within six months(Start date is 1/1/2020, so max date is 7/1/2020). Then 04/07/2020 and 05/10/2020 will return false.
Please correct me if I'm wrong.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@Anonymous , Try measure like
//Date1 is independent Date table
new measure Users Won =
var _max = maxx(allselected(Date1),Date1[Date]) // Or use Today
var _min = eomonth(_max, -6) +1
return
calculate( distinctCOUNT(Table[User]), filter('Table', 'Table'[Prize Date] >=_min && 'Table'[Prize Date] <=_max && Table[Start Date]<= _max && Table[End date] >= _min))
or
//Date1 is independent Date table
new measure Prize Won =
var _max = maxx(allselected(Date1),Date1[Date]) // Or use Today
var _min = eomonth(_max, -6) +1
return
calculate( COUNT(Table[User]), filter('Table', 'Table'[Prize Date] >=_min && 'Table'[Prize Date] <=_max && Table[Start Date]<= _max && Table[End date] >= _min))
User | Count |
---|---|
15 | |
13 | |
8 | |
6 | |
6 |
User | Count |
---|---|
24 | |
19 | |
12 | |
9 | |
7 |