Hi Mynda and team!
I've been working with Power Query within the last couple of months, and now I've run across having to figure out custom column formulas using this language. I've reviewed the blog on conditional formulas for nested ifs, which is very helpful. But not sure how to manage what I need for this, which is something I need to calculate often.
What I'm trying to do is replicate a change or variance column based on values from one time frame to another. In this case, I have year-over-year columns for prior year and current year.
Typically, I would write the formula in Excel or a similar calculated pivot column that would translate to something like this:
First if condition: if(Cases_PY = 0 then
2nd if condition (true part): if(Cases_CY >0 then 1 else 0)
back to 1st condition (false part): (Cases_CY-Cases_PY)/Cases_PY
Otherwise 0
So, this says that if prior year cases are 0 then validate if current year cases are >0. If so, then provide "1" (or 100%). If not, then the 2nd condition will result in 0.
But if 1st condition is not 0, then do the formula. This is to avoid the divisor !=0 error.
Is there a way to translate this to a column in power query? I have a few of them to write that will match this logic.
Also, is it necessary to setup a Difference column for the current and prior years values instead of doing it in the formula?
** Additional question: I meant to ask if I were to setup the calculated field in PowerPivot if it would be dynamic in Power View reports/charts? Will it update based on the slicers and filters?
Thanks for your assistance!
Robin
Hi Robin,
Great to hear you're making use of Power Query!
Without an example file it's difficult to say, but it sounds like your data isn't in a tabular format. The formula you describe isn't something that should be done in Power Query because your data should not have separate value columns for the different years/periods.
In a tabular format, which is what should be in Power Query, you would have a column for the date and a column for the value. It's then in PivotTables that you then group and summarise the data into periods, and this is also where you do these year on year calculations.
Power Pivot is ideal for this type of calculation (measure) and they can be set up to dynamically update and recalculate based on filters and Slicers. And, yes they will also automatically update in your Power View reports/charts.
So, it sounds like you need to now load your (tabular) Power Query data into Power Pivot and learn how to write DAX measures. I have a Power Pivot course if you need.
Let me know if you have any questions.
Mynda