Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Dear DAX cracks,
I have a list of employees in our facility that is updated every month. In a reduced form, it looks like this:
Name | Given Name | Month | Year |
Smith | John | 4 | 2021 |
Smith | John | 5 | 2021 |
Smith | John | 6 | 2021 |
Smith | John | 7 | 2021 |
Muller | Alex | 5 | 2021 |
Muller | Alex | 6 | 2021 |
Davis | Sam | 7 | 2021 |
As you can see, Alex Muller joined in May and Sam Davis was hired in July.
I was asked to prepare a calculated table that shows the new hires based on a time slicer. E.g. If I wanted to show the additional hires from between April and August July, it should output Alex Muller and Sam Davis. In another calculated table I'd like to have the exits in a certain time period.
My idea would be to calculate 2 interim tables, one containing the facts of the the starting month and the other having the end month data and then do something like a right outer join with the two interim tables in the first case and a left outer join in the second. But I don't understand how to achieve this in DAX. Any advice? Thank you!
Solved! Go to Solution.
@bkr
"E.g. If I wanted to show the additional hires from between April and August July, it should output Alex Muller and Sam Davis."
I guess you meant if you choose May to July here, because John Smith is also a new in April. I create a calculated table to achieve this, basically you just need find the join month of each people.
Table 2 = SUMMARIZE('Table',[Given Name],[Name],[Year],"Join Month",CALCULATE(MIN('Table'[Month]),ALLEXCEPT('Table','Table'[Name])))
@bkr
"E.g. If I wanted to show the additional hires from between April and August July, it should output Alex Muller and Sam Davis."
I guess you meant if you choose May to July here, because John Smith is also a new in April. I create a calculated table to achieve this, basically you just need find the join month of each people.
Table 2 = SUMMARIZE('Table',[Given Name],[Name],[Year],"Join Month",CALCULATE(MIN('Table'[Month]),ALLEXCEPT('Table','Table'[Name])))
@bkr , You can not use slicer values in a calculated table. But you can do it in a measure. Please make sure you have date and full name or ID
sales =
var _max = maxx(allselected('Date'),'Date'[Date])
var _min = minx(allselected('Date'),'Date'[Date])
var _hire = calculate(Min(Table[Date]), allexcept(Table, Table[Full Name]) )
return
calculate(countx(filter(values(Table[Full name]) , _hire <=_max && _hire >= _min)))
Thank you very much! I tried to transfer your solution on my data model. However, it's asking for another argument for the countx function in the last line. Is there anything missing here?
Ok, I think I got what wou wanted to write - I assume the last line should read
calculate(countx(filter(values(Table[Full name]) , _hire <=_max && _hire >= _min), Table[Full Name]))
This gives me a number. But what I need is a list of the Names of the new hires.
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
23 | |
21 | |
20 | |
13 | |
12 |
User | Count |
---|---|
41 | |
31 | |
23 | |
23 | |
22 |