The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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.
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
User | Count |
---|---|
21 | |
19 | |
19 | |
18 | |
14 |
User | Count |
---|---|
42 | |
35 | |
24 | |
20 | |
19 |