Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
jessica_webb
Creator III
Creator III

Multi-level calculation using set analysis/variables

Hi,

As you may have been able to tell from the title, I'm not quite sure how to go about this, so I'm hoping that someone with a bit of expertise could help!

I basically want to end up with a straight table, with six separate calculations, which build on each other.

The first six columns of my example table are the data I'm loading in, the last six (in purple) are the results I'm hoping to achieve in QV.

          

IDTypeSizeNameScoreOldNewR1R2R3R4R5R6
1877A10140.6729300.080.08-0.51-2.53-1.25-1.25
3206A10140.002820-0.82-0.82-0.51-2.53-1.25-1.25
7633A10140.672920-0.92-0.92-0.51-2.53-1.25-1.25
9454A10143.3333400.710.28-0.51-2.53-1.25-1.25
9816A10137.602610-1.58-1.58-0.51-2.53-1.25-1.25
3917A10242.673020-0.99-0.640.010.04-1.25-1.25
6319A10239.3323300.700.350.010.04-1.25-1.25
8833A10244.673430-0.40-0.400.010.04-1.25-1.25
9454A10243.333130-0.140.280.010.04-1.25-1.25
9828A10248.6741500.860.860.010.04-1.25-1.25
2670B5143.331410-0.42-0.42-0.48-1.45-1.26-1.25
3917B5142.671310-0.30-0.64-0.48-1.45-1.26-1.25
6319B5139.331010-0.010.35-0.48-1.45-1.26-1.25
4436B5241.3380-0.75-0.75-0.49-0.98-1.26-1.25
6219B5240.677100.260.26-0.49-0.98-1.26-1.25

R1: =(New - Old)/Size

R2 = Average of R1 for each distinct ID

R3 = Sum of R1 for each distinct Name / Count of all (non distinct) IDs in that distinct Name

R4 = R3 for each distinct Name x Count of all (non distinct) IDs in that distinct Name

R5 = Sum of R4 for each distinct Type / Count of all (non distinct) IDs in that distinct Type

R6 = Sum of R4 / Count of all (non distinct) IDs

Unsurprisingly, I've managed to workout how to calculate R1 myself (New-Old)/Size

But that's it...

The list of IDs, Types, and Names is endless, so I don't want to have to refer to (e.g.) 'Type=A' anywhere, if I can avoid it.

I toyed with the idea of creating a variable from my R1 expression, but then realised that I'm a bit out of my depth, so thought I'd be best off seeing if anyone had any better suggestions first!

Any suggestions would be greatly appreciated - please let me know if you need any additional information.

12 Replies
jessica_webb
Creator III
Creator III
Author

Thank you again!

It definitely is getting pretty complex - slightly out of my depth I think!

Actually, none of it depends on user selections. I had thought about doing it in the script, but I have even less experience of doing that.

I did try before with

LOAD

R1 as (New-Old) / Size);

But gave up pretty quickly when that didn't work.

I'll take a look at those articles, try and load the calculations in the script, and fingers crossed won't bother you again!


Many thanks,

Jess

swuehl
MVP
MVP

You would not be able to do the same aggregations with TOTAL in the script, you would need to create temporary tables with the proper granularity and aggregation functions and then join these tables back to your original table, somehow like I described in my first response.

If you want to create new fields, the syntax is like

LOAD

     calculation AS NewFieldName,

e.g.

LOAD

(New-Old) / Size) AS R1,

jessica_webb
Creator III
Creator III
Author

Now working perfectly.

Looks like your first response was actually the one that was spot on for me!

Thanks once again for all your help with this,

Jess