Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hello,
I have a table with employees and their yearly salary over 4 years. In this table I need a calculated column which would show the latest salary amount based on a date in another column in the same row. If the latest amount is zero or empty cell, it needs to find the next most recent amount and use this number instead.
So basically something like: if (and (current amount=0,date = latest date), find previous amount, current amount)
There are only four dates in the data set. 31.10.2019, 31.10.2020, etc.., so basically 4 rows per person for those who have been in the company for all four years.
This is an example of the dataset:
Does anyone have experience with something like this?
Solved! Go to Solution.
@Uspace87 Just to let you know -After trial and error I found a solution for my case. I added the column in DAX using the following formula:
I have changed the formula, can you try this:
Thanks very much @Uspace87!
I tried your formula, but I am probably doing something wrong. I get the following error message:
Could you please see what the problem is? And will this formula actually give me a new column? Or is it just a measure? Thanks again!
Hi,
I have used to a calculated column. Are you creating a measure? That could be the reason why you get the error.
@Uspace87 Just to let you know -After trial and error I found a solution for my case. I added the column in DAX using the following formula:
@Uspace87 Unfortunately the problem must be somewhere else, I am trying to get a new column just like you.
EarliestSalary = CALCULATE( MIN('Employee'[Salary]), FILTER( ALL('Employee'), 'Employee'[EmployeeID] = EARLIER('Employee'[EmployeeID]) && 'Employee'[Salary] <> BLANK() ) )
Yes, you can create a calculated column in Power BI to achieve this. Here's an example of the DAX formula you could use:
In this formula, the VAR statements define variables that hold the current date and salary amount for the employee being evaluated. The FILTER function then searches the entire Employee table for rows that match the employee's name and have a date that is less than or equal to the current date and a non-empty salary amount. The MAXX function then returns the highest salary amount from the filtered rows, which is the latest non-zero salary. Finally, the IF statement checks if the current salary amount is blank or zero and returns the latest non-zero salary if it is, or the current salary amount if it isn't.
You can replace "Name" and "Date" with the appropriate column names in your dataset, and "Amount" with the name of your salary column.
@MAwwad Thanks for this! I have similar measure the the one you are giving me. That works fine in DAX. The problem is that this only gives me the measure and not value in each row which I am after. My formula that works looks like this.
Sure, I can help you modify your DAX formula to add a new column into your dataset instead of just returning a measure.
To do this, you can use the DAX function ADDCOLUMNS. This function allows you to create a new table by adding new columns to an existing table. Here's an example of how you can modify your formula to add a new column called "Adjusted Salary" to your 'PBI Compensation' table:
This formula creates a new table by adding four new columns: "PreviousDate", "PreviousSalary", "CurrentSalary", and "Adjusted Salary" to the 'PBI Compensation' table. The "Adjusted Salary" column is calculated using the same logic as your original measure.
Note that the "PreviousDate", "PreviousSalary", and "CurrentSalary" columns are intermediate columns that are used to calculate the final "Adjusted Salary" column. You can remove these intermediate columns from the formula if you don't need them in your final result.
I hope this helps!
Thanks for all your time @MAwwad! This solution is exactly would I am looking for! However when I apply the formula I get an error:
Do you have a suggestion how to solve this? Thanks again!
Hi,
please post some sample data
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
15 | |
15 | |
13 | |
12 | |
11 |