Forum Discussion
Creating a column based off current year values with 3yr/5yr indicators
Hello all, I've been stuck on this problem for a day now and I'm looking for some input. I am very new to M language and I'm trying to make what I think is a simple column with it, essentially using 2 if statements. In pseudocode my logic is like this:
if [yrColumn] >= currentYear -3 then "A"
else
if [yrColumn] >= currentYear -5 then "B"
else "C"
I would then make a new conditional column that says something like
If value = A then "3yr view"
if value = A and B then "5yr view"
I'm not certain if this will work since I'm trying to apply 2 values to years that fall within 3 and 5. For example 2018 would need to show up in both 3 and 5, but I can only apply a single value to the row. Ideally how this would work overall is that the values would update once a year so every year change would have new 3yr and 5yr values automatically.
Is this possible?
Hello Anonymous
add a new column with this formula for 3 years
if [yrColumn] >= Date.Year(Date.AddYears(DateTime.FixedLocalNow(),-3)) then true else falsethis is the result
add another column where you put -5 instead of -3.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
4 Replies
- Jimmy801Community Champion
Hello Anonymous
and why are you not adding two column... one calles Is3Year and the oth Is5Year and filling it with true or false?
what is the scope of this conditional columns?
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy- AnonymousNot applicable
Thanks Jimmy801 for the suggestion.
That is another great alternative that may work better. Can you help with the M code to signify a 3 or 5yr T/F?- Jimmy801Community Champion
Hello Anonymous
add a new column with this formula for 3 years
if [yrColumn] >= Date.Year(Date.AddYears(DateTime.FixedLocalNow(),-3)) then true else falsethis is the result
add another column where you put -5 instead of -3.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy