Forum Discussion

coollehavre's avatar
coollehavre
Frequent Visitor
1 year ago
Solved

find previous value in a snapshot table

Hi everyone,

i have a snapshot table (same employees every month in a single table) and i need to compare job_id for an employee from previous month 

 

i would like to create a calculated column or measure (job_id_previous_month) like this : 

 

employee_idjob_idsnapshot_datejob_id_previous_month
E001J12331/01/2024 
E002J23031/01/2024 
E003J23031/01/2024 
E001J23528/02/2024J123
E002J23028/02/2024J230
E003J23028/02/2024J230

 

Any help to do this ? 

 

Thanks 

  • Hi,

    Please check the below picture and the attached pbix file.

     

     

     

    job_id_previous_month CC =
    VAR _currentrowemployee = data[employee_id]
    VAR _currentrowmonth = data[snapshot_date]
    RETURN
        MAXX (
            FILTER (
                data,
                data[employee_id] = _currentrowemployee
                    && data[snapshot_date] = EOMONTH ( _currentrowmonth, -1 )
            ),
            data[job_id]
        )
    
  • Hello coollehavre , 

     

    Please try the below code..

     

    job_id_previous_month =
    VAR currentEmployee = 'Table'[employee_id]
    VAR currentDate = 'Table'[snapshot_date]
    RETURN
    CALCULATE(MAX('Table'[job_id]),FILTER('Table','Table'[employee_id] = currentEmployee &&

    EOMONTH('Table'[snapshot_date], 0) = EOMONTH(currentDate, -1)))

     

     

    If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes are much appreciated!

     

    Thank You

    Dharmendar S

    LinkedIN 

     

3 Replies

  • Hi,

    Please check the below picture and the attached pbix file.

     

     

     

    job_id_previous_month CC =
    VAR _currentrowemployee = data[employee_id]
    VAR _currentrowmonth = data[snapshot_date]
    RETURN
        MAXX (
            FILTER (
                data,
                data[employee_id] = _currentrowemployee
                    && data[snapshot_date] = EOMONTH ( _currentrowmonth, -1 )
            ),
            data[job_id]
        )
    
  • dharmendars007's avatar
    dharmendars007
    Icon for Memorable Member rankMemorable Member

    Hello coollehavre , 

     

    Please try the below code..

     

    job_id_previous_month =
    VAR currentEmployee = 'Table'[employee_id]
    VAR currentDate = 'Table'[snapshot_date]
    RETURN
    CALCULATE(MAX('Table'[job_id]),FILTER('Table','Table'[employee_id] = currentEmployee &&

    EOMONTH('Table'[snapshot_date], 0) = EOMONTH(currentDate, -1)))

     

     

    If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes are much appreciated!

     

    Thank You

    Dharmendar S

    LinkedIN