Forum Discussion
Converting quarters & years into numerical values
Oh, Do you want to add a calculated column?
You can use my codes as a Measure, not a new Column.
If you want a column, use this code:
Time in Years = Var _Len = LEN(Base[Time] )-4 RETURN IF( CONTAINSSTRING(Base[Time],"Q") , RIGHT(Base[Time],_Len)/4, IF( CONTAINSSTRING(Base[Time],"Y") , RIGHT(Base[Time],_Len)/1 ) )If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
9 Replies
- VahidDM
Super User
Hi YusufHabib
Try this measure:
Time in Years = VAR _2R = RIGHT ( MAX ( Base[Time] ), 2 ) VAR _Y_Q = LEFT ( _2R, 1 ) VAR _N = RIGHT ( _2R, 1 ) RETURN IF ( _Y_Q = "Q", _N / 4, _N )Output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
- YusufHabibNew Member
Thanks for the quick answer but the query doesn't work for PD_Q10 or PD_Y10. Is there a way to make it work in those cases?
- VahidDM
Super User
Hi YusufHabib
Try this:
Time in Years = Var _Len = LEN(MAX ( Base[Time] ))-4 VAR _2R = RIGHT ( MAX ( Base[Time] ), _Len+1 ) VAR _Y_Q = LEFT ( _2R, 1 ) VAR _N = RIGHT ( _2R, _Len) RETURN IF ( _Y_Q = "Q", _N / 4, _N )Output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
- Fowmy
Super User
YusufHabib
Not clear about the expected results but can you try thisTime in Years = IF( CONTAINSSTRING(Base[Time],"Q") , RIGHT(Base[Time],1)/4, IF( CONTAINSSTRING(Base[Time],"Y") , RIGHT(Base[Time],1)/1 ) )- YusufHabibNew Member
Thanks for the quick answer but the query doesn't work for PD_Q10 or PD_Y10. Is there a way to make it work in those cases?
- Fowmy
Super User
YusufHabib
I posted my solution as well, this will accommodate any size of the text before Q or Y:Time in Years = VAR __LEN = LEN(Base[Time]) VAR __LOC_Q = SEARCH("Q",Base[Time],,0) VAR __LOC_y = SEARCH("Y",Base[Time],,0) RETURN IF( __LOC_Q > 0 , RIGHT(Base[Time],__LEN - __LOC_Q)/4, IF( __LOC_y > 0, RIGHT(Base[Time],__LEN - __LOC_y)/1 ) )