Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Getting Monthly Data from effective day

Dear all,

 

I have a though task at hand.

 

I have a table like this:

 

Employee IDJob Information DateDepartment
101/01/2019Alfa
115/01/2019Beta
128/02/2019Gamma

 

That means that "Employee 1" was in "Alfa" team btw January 1st and January 31st. On the 31st of January, he moved to "Beta" team and stayed there until 28th of Feb, then on the 28th of Feb, he moved to Gamma team. Since there's no change in his job information since then, he's still in the Gamma team as we understand. Let's say today it's 31st of March, so we know that Employee 1 is still working in the Gamma team

 

Based on this, I'd like to create a table like this where I can see the number of days per month spent in a department:

 

Employee IDYearMonthNumber of daysDepartment
12019January15Alfa
12019January16Beta
12019February28Gamma
12019March31Gamma

 

Do you think that it's managable (preferably within M language)?

 

Thank you for your help in advance.

 

Regards,

Ugur

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi,

     

    I assume you would be able to Create an Index Comn in your Table. This Column would have the list of numbers in the Increasing Sequence.

     

    Now use the Following Measure

     

    ADDCOLUMNS(SUMMARIZECOLUMNS(Employee_ID,"Year", YEAR(Date),"Month",MONTH(Date)),"Difference in Days",

    VAR Next_Index=Table[Index]+1

    VAR Index=Table[Index]

    RETURN CALCULATE(DATE,FILTER(TABLE,Table[Index]=Index))- CALCULATE(DATE,FILTER(TABLE,Table[Index]=Next_Index))))

     

    You could also use the DateDiff function but I dont think it would accept Expressions as a part of the Date Arguments.

    RETURN DATEDIFF