Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Dear All,
My name is Ruud and I am preparing a dashboard for an external company. Because of privacy, I have prepared a similar data set that shows the problem that I have at the moment.
Context: for this company I am trying to calculate the total sum of hours worked, and the total sum of target hours that one has to work in a specific period.
The first one is not a problem, however the second one I have troubles with by the way they register their data.
The problem: In the targeted hours, they include hours for each day for the whole year (except for weekend days). The problem occurs when a person does not work the whole year, for the reason that he or she leaves the company or enters the company at a specific moment during the year.
What I would like to have:
I want a measure that calculates the sum of total targeted hours per person with their specific contract- start and end date. In other words, if a person started after the first date in the calendertable, then the targeted hours present before this date should not be included.
Likewise, if the end date is before todays date, then the hours after the contract_end date to todays moment should now be included.
The file:
In the Data I focused my problem on user ‘A1’. His contract date starts at 05-03-2020 and end beyond our todays date. However, the targeted hours start counting from 05-01-2020. Therefore, there are two months included in the sum of targeted hours that should not be there.
Thank you for your time,
Cheers,
Ruud Scheijen
https://drive.google.com/file/d/1KfPdIVPzgqQr-YXyGGNz5kaRYn_4JrI3/view?usp=sharing
Solved! Go to Solution.
Hi @StatStories_Lon ,
Try this measure:
Hi @StatStories_Lon ,
Try this measure:
I have a question. Can a User_ID have more than one contract..? they do not in your sample data. Which suggests that Dim_Users and Dim_Contracts could be combined... giving you a star schema instead of a snowflake. That will probably make writing the measure you want easier.
Help when you know. Ask when you don't!
Thank you for your reaction.
It appears that there are users with more than one contract. Thus one userid with multiple start & end dates.
Thank you for your reaction.
I did not know, but it appears that there are users with more than one contract. Thus one userid with multiple start & end dates.
** In this case, we need to consolidate every contract (using summarize) before sum them.**
How would this work then?
First summarizing the userid, contractstartdate, contractenddate, and in turn apply your suggested steps?
I tried this code:
ContractId | Start_Date | End_Date | UserId |
4 | 3 janeiro, 1991 | sábado, dezembro 31, 2022 | A4 |
6 | 5 janeiro, 1991 | sábado, dezembro 31, 2022 | A4 |
Will both contracts be applied for the targets ?
Target | medewerker_id | Datum | Target Hours |
69 | A4 | domingo, março 8, 2020 | 6 |
Well this is not possible in the real case. The first contract_end_date will be before the second contract_start_date.
This is probably a mistake I made when creating the sample data.
**
SUMMARIZE(Dim_Contract; Dim_Contract[ContractId]; Dim_Users[UserId]; Dim_Contract[Start_Date]; Dim_Contract[End_Date]; "Qtde Hours";
**
In your example what is "Qtde Hours?
Hi @StatStories_Lon ,
This is just as alias for this formula:
Thank you for your help so far.
I tried your code, but Power Bi shows me this message:
"The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value".
Do you know why it shows me this?
Hi @StatStories_Lon ,
Try this measure:
Thank you very much! This was the solution!
May you have a very nice day and week 🙂
Ruud
I occured another problem with this measure.:
It seems that I cannot filter it by a date component. For example, when I want to see the "Total Target Hours" per month, this will not filter it accordingly and just shows the sum of this measure.
Is it possible that it can't be filtered because it is based on date columns?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
107 | |
99 | |
76 | |
64 | |
58 |
User | Count |
---|---|
148 | |
113 | |
97 | |
84 | |
67 |