Forum Discussion
how to compare row values based on multiple criteria
- 6 years ago
Anonymous
Hi, Add the following DAX code as a new column in your table and correct the table and column names as necessary.Job Change Status = VAR U = [User ID] VAR Y = [Job Year] VAR _TABLE = FILTER( ADDCOLUMNS( FILTER ( GENERATE ( 'merit 18-21', SELECTCOLUMNS ( 'merit 18-21', "2YR", 'merit 18-21'[Job Year], "2BAND", 'merit 18-21'[band], "2JOB", 'merit 18-21'[JobCode2], "2USER", 'merit 18-21'[User ID] ) ), 'merit 18-21'[User ID] = [2USER] && 'merit 18-21'[Job Year] = [2YR] + 1 ), "Job Change", SWITCH( TRUE(), NOT('merit 18-21'[band] > [2band]) && 'merit 18-21'[JobCode2] = [2JOB], "NO CHANGE", 'merit 18-21'[band] > [2band], "PROMOTION", NOT('merit 18-21'[band] > [2band]) && 'merit 18-21'[JobCode2] <> [2JOB], "LATERAL JOB MOVEMENT", "STATUS NOT IDENTIFIED" ) ), 'merit 18-21'[User ID] = U && 'merit 18-21'[Job Year] = Y ) RETURN MAXX(_TABLE,[Job Change])________________________
Did I answer your question? Mark this post as a solution, this will help others!.
Click on the Thumbs-Up icon if you like this reply 🙂
Hi Greg,
I want to achieve is to compare employee's job code and band year by year,
if the band has increased from previous year to current, that means the employee receives a promotion,
if the band has remained the same/decreased, and the job code remain the same, the employee goes through a laternal job movement,
if band remained the same/decreased and job code remains the same, the employee's job has not changed.
I know it's easy to the embedded if functoin in Excel, but given everything is automated in Power BI so far, i don't want to add a manual input formula here.
Anonymous
Your 2nd and 3rd conditions are the same I believe, can you check?
________________________
Did I answer your question? Mark this post as a solution, this will help others!.
Click on the Thumbs-Up icon if you like this reply 🙂
- Anonymous6 years agoNot applicable
My apologies for the typo in my statement. It is corrected below. However, that doesn't explain why the DAX formula fails, i have tested it, it looks the value() part has caused a syntax error.
if the band has increased from previous year to current, that means the employee receives a promotion,
if the band has remained the same/decreased && the job code has changed from previous year, the employee goes through a laternal job movement,
if band remained the same/decreased and job code remains the same, the employee's job has not changed.
- Fowmy6 years ago
Super User
Anonymous
Hi, Add the following DAX code as a new column in your table and correct the table and column names as necessary.Job Change Status = VAR U = [User ID] VAR Y = [Job Year] VAR _TABLE = FILTER( ADDCOLUMNS( FILTER ( GENERATE ( 'merit 18-21', SELECTCOLUMNS ( 'merit 18-21', "2YR", 'merit 18-21'[Job Year], "2BAND", 'merit 18-21'[band], "2JOB", 'merit 18-21'[JobCode2], "2USER", 'merit 18-21'[User ID] ) ), 'merit 18-21'[User ID] = [2USER] && 'merit 18-21'[Job Year] = [2YR] + 1 ), "Job Change", SWITCH( TRUE(), NOT('merit 18-21'[band] > [2band]) && 'merit 18-21'[JobCode2] = [2JOB], "NO CHANGE", 'merit 18-21'[band] > [2band], "PROMOTION", NOT('merit 18-21'[band] > [2band]) && 'merit 18-21'[JobCode2] <> [2JOB], "LATERAL JOB MOVEMENT", "STATUS NOT IDENTIFIED" ) ), 'merit 18-21'[User ID] = U && 'merit 18-21'[Job Year] = Y ) RETURN MAXX(_TABLE,[Job Change])________________________
Did I answer your question? Mark this post as a solution, this will help others!.
Click on the Thumbs-Up icon if you like this reply 🙂
- NMK0153 years agoNew Member
Tried replicating the same but getting below error
DAX comparison operations do not support comparing values of type Text with values of type Number. Consider using the VALUE or FORMAT function to convert one of the values.
- Anonymous6 years agoNot applicable
HI Anonymous ,
job change = VAR prevBand = MAXX(filter('merit 18-21', 'merit 18-21'[User ID] =EARLIER('merit 18-21'[User ID]) && 'merit 18-21'[Job Year] = EARLIER('merit 18-21'[Job Year])-1)),'merit 18-21'[band]) VAR CurrentBand = MAXX(filter('merit 18-21', 'merit 18-21'[User ID] =EARLIER('merit 18-21'[User ID]) && 'merit 18-21'[Job Year] = EARLIER('merit 18-21'[Job Year])),'merit 18-21'[band]) VAR prevJob = CALCULATE(MAX('merit 18-21'[JobCode2]), filter('merit 18-21', 'merit 18-21'[User ID] =EARLIER('merit 18-21'[User ID]) && 'merit 18-21'[Job Year] = EARLIER('merit 18-21'[Job Year])-1)) VAR currentJob=CALCULATE(MAX('merit 18-21'[JobCode2]), filter('merit 18-21', 'merit 18-21'[User ID] =EARLIER('merit 18-21'[User ID]) && 'merit 18-21'[Job Year] = EARLIER('merit 18-21'[Job Year]))) RETURN SWITCH( TRUE(), //prevBand < CurrentBand, "Promotion", //prevJob <> CurrentJob,"Lateral Movement", //"no change") prevBand //CurrentBand //prevJob //CurrentJobTry troubleshooting removing the commented value one by one and see if you are getting the correct values.
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)- Anonymous6 years agoNot applicable
Thanks for coming back, Harsh.
I made a bit update to remove syntax error (see below), the commands works with no error message, but the result is not correct. It doesn't work when there is no previous data (e.g., only 2018 data exist for user id 00001).
I'm also wondering if MAX formula will work when it deals with a text column (here column JobCode2)?
job change =VAR prevBand = MAXX(filter('merit 18-21', 'merit 18-21'[User ID] =EARLIER('merit 18-21'[User ID]) && 'merit 18-21'[Job Year] = EARLIER('merit 18-21'[Job Year])-1),'merit 18-21'[band])VAR CurrentBand = MAXX(filter('merit 18-21', 'merit 18-21'[User ID] =EARLIER('merit 18-21'[User ID]) && 'merit 18-21'[Job Year] = EARLIER('merit 18-21'[Job Year])),'merit 18-21'[band])VAR prevJob = CALCULATE(MAX('merit 18-21'[JobCode2]), filter('merit 18-21', 'merit 18-21'[User ID] =EARLIER('merit 18-21'[User ID]) && 'merit 18-21'[Job Year] = EARLIER('merit 18-21'[Job Year])-1))VAR currentJob=CALCULATE(MAX('merit 18-21'[JobCode2]), filter('merit 18-21', 'merit 18-21'[User ID] =EARLIER('merit 18-21'[User ID]) && 'merit 18-21'[Job Year] = EARLIER('merit 18-21'[Job Year])))RETURNSWITCH(TRUE(),prevBand < CurrentBand, "Promotion",prevJob <> CurrentJob,"Lateral Movement","no change")//prevBand//CurrentBand//prevJob//CurrentJob)