# verification the formula of calculation a measure #370

Closed
opened this Issue May 8, 2018 · 14 comments

Projects
None yet
3 participants

### chifaanfar commented May 8, 2018

 hey ! i want to test if a mesureX is equal to mesureA / mesureB , there is a way to test it using NBi ? i found this section in the NBi documentation : Expression and predicate " http://www.nbi.io/docs/resultset-predicate/" but i don't know how to apply it in my case .

Owner

### Seddryck commented May 9, 2018

 Indeed performing this kind of test isn’t intuitive and a better support is expected soon. You should define an expression « checkMeasureX » with `measureA/measureB` Then a second expression « equalX » with `checkMeasureX=MeasureX` Then finally a predicate `true` operating on `equalX`. Is it clear? If not I’ll need more than my smartphone to give a complete example and it will wait until this weekend.

### FuegoArtificial commented May 9, 2018

 If you have the possibility to query your database you can also apply a comparison between two query results. One returning the measure, one returning the explicit calculation of the measure.

### chifaanfar commented May 10, 2018

 thank you @Seddryck , but what should i put in the "system under test" , should i specify the mesures "SELECT {[\$Measures\$].[\$MesureA\$], [\$Measures\$].[\$MesureB\$], [\$Measures\$].[\$MesureX\$]}ON 0 FROM [MYCUBE]" or just write the connectionString , @FuegoArtificial thanks for your return , i want to create a template that generalize this kind of test , and that can be applicable to all my test of verification the formula of calculation , so using two query can not be usefull in my point of view , but if you have an exemple I will be very grateful :D
Owner

### Seddryck commented May 10, 2018

 Yes, the system under test should be a query. … On 10 May 2018, at 12:17, chifaanfar ***@***.***> wrote: thank you @Seddryck , but what should i put in the "system under test" , should i specify the mesures "SELECT {[\$Measures\$].[\$MesureA\$], [\$Measures\$].[\$MesureB\$], [\$Measures\$].[\$MesureX\$]}ON 0 FROM [MYCUBE]" or just write the connectionString , @FuegoArtificial thanks for your return , i want to create a template that generalize this kind of test , and that can be applicable to all my test of verification the formula of calculation , so using two query can not be usefull in my point of view , but if you have an exemple I will be very grateful :D — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

### chifaanfar commented May 10, 2018

 i tried to excecute this test but it doesn't work , surely it's wrong , so i will wait until this weekend to give me an example as expected , thank you again Seddryck

### FuegoArtificial commented May 11, 2018

 For this specific kind of test I generalized the query as a whole. When creating the test I develop two queries one with the measure(s), another one with the calculation(s) as calculated members. These two queries I add to the template. The next test takes two queries again. Furthermore the test name and categories are set as parameters, too. For me and my colleagues that level of generalization is the sweet spot of simplicity/flexibility/maintainability to write such tests, also when it comes to slicing the data for testing semi additive-measures. However, it might be different for you, of course, especially if you want to avoid that testers have to write queries. Perhaps, I have a slightly different approach, where I let testers not hassle with the XML at all and everything is set into the templates with meta data (queries, etc.) and test-generation with genbi. With other kinds of tests like testing for the count of dimension members, templates are easier to generalize without using queries due to the powerful support of certain kinds of tests with nbi. I might miss something here and am open for suggestions, too! :)
Owner

### Seddryck commented May 13, 2018

 I published a blog about how to resolve this kind of case at https://seddryck.wordpress.com/2018/05/13/using-nbi-to-assert-calculations-based-on-measures/ I'll update it to cover the automation but will wait until Monday evening more than probably.

### chifaanfar commented May 14, 2018

 Thank you Seddryck , it's very interessting , waiting for the automation part @FuegoArtificial i have the same approach , the goal of my project is to minimise the fact that testers have to write queries , and to set everything into the templates
Owner

### Seddryck commented May 15, 2018

 I updated the post with the template, the genbiL script and some explanations about them. Note that due to unfair circonstances there is a bug in the serialization of expression in NBi and you should use the last beta: https://ci.appveyor.com/project/Seddryck/nbi/build/1.19.0-beta.9.build.396

### chifaanfar commented May 16, 2018

 thanks you a lot Seddryck for your effort i tried to execute my test with the last version V1.18 to avoid the bug in serialization , but I came across an error of another type :( i used the same Template and Macro defined in the blog
Owner

### Seddryck commented May 16, 2018

 I’m sorry but your screenshot clearly shows that your script is executed twice. Is it really a screenshot related to this script ... I doubt! Could you post your files for the script, the template and test cases in place of screenshots?

### chifaanfar commented May 16, 2018

 yes of course testcase alias;expression;measure;round call,volume,Alloc;volume/call;[Measures].[Calls #] , [Measures].[Volume] , [Measures].[50 ALOC];2 template script case scope 'First Set'; case load file 'D:\NBi-1.18.0.1\MyTestProject\CSV\calculations.csv'; case split column 'alias' with value ','; case split column 'measure' with value ','; setting reference 'ref-one' connectionString '@ORIGIN_DEV'; template load file 'D:\NBi-1.18.0.1\MyTestProject\calculation.nbitt'; case cross 'First Set' with vector 'ref' values 'ref-one'; suite generate; suite save 'D:\NBi-1.18.0.1\MyTestProject\calculation.nbits';
Owner

### Seddryck commented May 17, 2018

 For your background, when you post a screenshot and not the content of a file, you’re enforcing people who are trying to help you to rewrite the content of your file. It could be leading to differences but it’s also not consider as respectful of their own time. To publish code you need to enclose it between three back ticks. (Check the syntax supported by github). That said, you didn’t answer my question: your first screenshot displays the execution of the genbiL script and there I can see that you are loading twice the CSV file. It’s not the case in the script that you provided. Could you explain that? Did you test the exact script that you posted here?
Owner

### Seddryck commented May 17, 2018 • edited

 I checked in details your code and your issue is related to the `case cross`. I opened the bug #376 and I developed a fix. There is also an easy work-around (and reason this bug was never detected), just move your `cross` before the first `split`.