Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
Hi all,
I need your help to create a column with returns the # of Months acculumated based on when an employee starts/returns from work.
Here's a sample table, where the last column "Months Accumulated" is the resulting column which I want to create:
| Company Branch | Employee | Entry Date | Contract Start Date | Months Accumulated |
| A | Bob | 2019-12-01 | 2017-10-01 | 17 |
| A | Bob | 2018-08-02 | 2017-10-01 | 10 |
| A | Jack | 2019-12-01 | 2018-05-01 | 19 |
| B | Hannah | 2019-12-01 | 2017-01-01 | 12 |
| B | Hannah | 2018-12-01 | 2017-01-01 | 24 |
ased on this, there are two conditions that would affect how the column "Months Accumulated" can be calculated:
- If Entry Date = Contract Start Date -> Entry Date - Contract Start Date
- If there's an existing entry record taking place before the considered row/entry date -> Considered Entry Date - Previous closest Entry Date
How best should I do this? Please help!
Thank you!
Solved! Go to Solution.
Hi @nerokasai ,
1. Insert an index column in power query.
2. Create the calculated column as below.
Column =
VAR ind = 'Table'[Index] + 1
VAR currecntemp = 'Table'[Employee]
VAR next =
CALCULATE (
MAX ( 'Table'[Employee] ),
FILTER (
'Table',
'Table'[Index] = ind
&& 'Table'[Company Branch] = EARLIER ( 'Table'[Company Branch] )
)
)
VAR nextentrydate =
CALCULATE (
MAX ( 'Table'[Entry Date] ),
FILTER (
'Table',
'Table'[Index] = ind
&& 'Table'[Company Branch] = EARLIER ( 'Table'[Company Branch] )
)
)
RETURN
IF (
currecntemp = next,
DATEDIFF ( nextentrydate, 'Table'[Entry Date], MONTH ) + 1,
DATEDIFF ( 'Table'[Contract Start Date], 'Table'[Entry Date], MONTH )
)
For more details, please check the pbix as attached.
Hi @nerokasai ,
1. Insert an index column in power query.
2. Create the calculated column as below.
Column =
VAR ind = 'Table'[Index] + 1
VAR currecntemp = 'Table'[Employee]
VAR next =
CALCULATE (
MAX ( 'Table'[Employee] ),
FILTER (
'Table',
'Table'[Index] = ind
&& 'Table'[Company Branch] = EARLIER ( 'Table'[Company Branch] )
)
)
VAR nextentrydate =
CALCULATE (
MAX ( 'Table'[Entry Date] ),
FILTER (
'Table',
'Table'[Index] = ind
&& 'Table'[Company Branch] = EARLIER ( 'Table'[Company Branch] )
)
)
RETURN
IF (
currecntemp = next,
DATEDIFF ( nextentrydate, 'Table'[Entry Date], MONTH ) + 1,
DATEDIFF ( 'Table'[Contract Start Date], 'Table'[Entry Date], MONTH )
)
For more details, please check the pbix as attached.
Hi @nerokasai
create the calculated column like this:
See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 45 | |
| 34 | |
| 27 | |
| 15 | |
| 15 |
| User | Count |
|---|---|
| 58 | |
| 55 | |
| 38 | |
| 21 | |
| 20 |