Hi,
in the fix version in jira I have the team and the capacity (hours per person) that is working on the fix version like this:
“Person A: 122h,Person B: 152h, Person C: 22h”
I would like to extract the hours and add them together in the calculated measure (I know I can do it during import as a custom field but I would highly prefer to do it in the calculated measure as the format of the string is still in flux so I can easily update this without reimport etc).
Using ExtractString I can extract the hours (and the names). Unfortunately, I have found no way to iterate over the hours (the number of team members is not constant but small, so below 10).
I got it working by unrolling the iteration (I extract 10 hour strings from the team string and add these, as there is less then 10 and as empty hours are counted a 0 I can just add these and get what I want) but this is really ugly:
CASE WHEN (ExtractString(ExtractString([Measures].[Fix Version Description],'.*Team:(.*)',1),'([^:]*: *(\d+)h,?){11}+',2)) <> ''
THEN
-1 -- throw error:'team cannot have more then 10 members ' || ...
ELSE
-- ugly hack: currently we support at most 10 team members as I have not found a
-- way to extract and accumulate the hours from the team string inside just one measure
Val(ExtractString(ExtractString([Measures].[Fix Version Description],'.*Team:(.*)',1),'([^:]*: *(\d+)h,?){1}+',2))+
Val(ExtractString(ExtractString([Measures].[Fix Version Description],'.*Team:(.*)',1),'([^:]*: *(\d+)h,?){2}+',2))+
Val(ExtractString(ExtractString([Measures].[Fix Version Description],'.*Team:(.*)',1),'([^:]*: *(\d+)h,?){3}+',2))+
Val(ExtractString(ExtractString([Measures].[Fix Version Description],'.*Team:(.*)',1),'([^:]*: *(\d+)h,?){4}+',2))+
Val(ExtractString(ExtractString([Measures].[Fix Version Description],'.*Team:(.*)',1),'([^:]*: *(\d+)h,?){5}+',2))+
Val(ExtractString(ExtractString([Measures].[Fix Version Description],'.*Team:(.*)',1),'([^:]*: *(\d+)h,?){6}+',2))+
Val(ExtractString(ExtractString([Measures].[Fix Version Description],'.*Team:(.*)',1),'([^:]*: *(\d+)h,?){7}+',2))+
Val(ExtractString(ExtractString([Measures].[Fix Version Description],'.*Team:(.*)',1),'([^:]*: *(\d+)h,?){8}+',2))+
Val(ExtractString(ExtractString([Measures].[Fix Version Description],'.*Team:(.*)',1),'([^:]*: *(\d+)h,?){9}+',2))+
Val(ExtractString(ExtractString([Measures].[Fix Version Description],'.*Team:(.*)',1),'([^:]*: *(\d+)h,?){10}+',2))
END
Second question, is there a way to “throw” and error in a calculated measure? It seems the types of both THEN and ELSE branch of the case statement need to be the same. I would want to “throw” an error in the first case so a string message which is displayed instead of the number telling the user (in the table). So that users are aware of the issue.
Finally, while asking about basics. Is there a way to define a temporary local variables inside a calculated measure for expressions that I want to reuse?
E.g. ‘ExtractString([Measures].[Fix Version Description],’.Team:(.)‘,1)’ in my code above I would want to comput eonly once and then reuse.