Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

What-if analysis and nested aggr

Hello,

I'm fairly new as QV developer and I'm trying to create an application whose purpose will be to do simulations with sliders objects.

I get what I want when I do simple computation but when I try to create new expression combining two simple working computation, it doesn't work.

I created a simplified application to explain my problem better.

Sorry if this message is a bit long, but I will try to write a clear introduction.

Data is stored like this :

DimensionProcessCostProbabilityValue
Step1ParamA * ParamB50%
Step1ParamC50%
Step2ParamD30%
Step3ParamD20%
Step3ParamE * ParamB20%
Step3ParamF20%

Parameters1CostDefaultValue1
ParamA5
ParamC5
ParamD10
ParamE0
ParamF1

Parameters2CostDefaultValue2
ParamB3

In this example : Cost of Step1 = Sum(Cost) = ParamA * ParamB + ParamC = 5 * 3 + 5 = 20

I can add parameters (like "_varParamA" and link it to a slider object) and create an expression like this :

Weighted Cost (Simulation) :

AVG(

        AGGR(

              SUM(CostDefaultValue1

                                     * if(ParamName2='Param A',_varParamA,

                                       if(ParamName2='Param B',_varParamB,

                                       if(ParamName2='Param C',_varParamC,

                                          CostDefaultValue2

                                          )))

                 ) * ProbabilityValue

             ,DimensionProcess))

This seems to work.

Now, I have another set of data:

DimensionProcessTimeProbabilityValue
Step1ParamG50%
Step1ParamH50%
Step2ParamI * ParamJ30%
Step3ParamK20%

ParametersTime1TimeDefaultValue1
ParamG20
ParamH1
ParamI4
ParamK1

ParametersTime2TimeDefaultValue2
ParamJ3

Like previously, I created an expression as this :

Elaspsed Time (Expected) :

SUM(aggr((sum(ProbabilityValue) / sum(total ProbabilityValue))

            * sum((if(ParametersTime1='Param 1',_varParamTime1,

                     if(ParametersTime1='Param G',_varParamTime2,

                      TimeDefaultValue1

                        ))

                      * TimeDefaultValue2))

            ,DimensionProcess))

This work as well.

Now, problem begins.

I want to combine both expressions to make my first expression influenced by the second one. I tried something like this :

AVG(

        AGGR(

              SUM(CostDefaultValue1

                                     * if(ParamName2='Param A',if([Elaspsed Time (Expected)]  > 30

                                                                        , _varParamA_high

                                                                   , if([Elaspsed Time (Expected)]  > 20

                                                                        , _varParamA_medium

                                                                   , _varParamA)),

                                       if(ParamName2='Param B',_varParamB,

                                       if(ParamName2='Param C',_varParamC,

                                          CostDefaultValue2

                                          )))

                 )  * ProbabilityValue

             ,DimensionProcess))

I think it doesn't work because it nests different "AGGR" expression (AVG(AGGR(SUM(!!!SUM(AGGR(....)))))).

I'm not very comfortable with Aggr() and maybe I'm completely wrong when I used it.

Do you think it's possible to achieve what I'm trying to do ?

Thank you in advance for any hints,

Jean

1 Solution

Accepted Solutions
Nicole-Smith

I added your other dimension (Param2) into your aggr() calculations and it changed the values; however, I don't know if it's correct or not.  So if this doesn't work and you need more help, please post what the values in that column are supposed to be.

AVG(

        AGGR(

              SUM(CostDefaultValue1

                                    * if(ParamName2='Param A',if(/*column(4)*/

                                                                  AGGR(SUM(if(TimeParamName1='Param 1',_varParamTime1,if(TimeParamName1='Param 2',_varParamTime2,TimeDefaultValue1))+ TimeDefaultValue2

                                                                            )

                                                                        ,Level1,Level2,Level3,ParamName2) > 30

                                                                        , _varParamA_high

                                                                  , if(AGGR(SUM(if(TimeParamName1='Param 1',_varParamTime1,if(TimeParamName1='Param 2',_varParamTime2,TimeDefaultValue1))+ TimeDefaultValue2

                                                                            )

                                                                        ,Level1,Level2,Level3,ParamName2) > 20

                                                                        , _varParamA_medium

                                                                  , _varParamA)),

                                      if(ParamName2='Param B',_varParamB,

                                      if(ParamName2='Param C',_varParamC,

                                          CostDefaultValue2

                                          )))

                )  * ProbabilityValue

            ,Level1,Level2,Level3,ParamName2)

  

      

)

View solution in original post

4 Replies
Nicole-Smith

I added your other dimension (Param2) into your aggr() calculations and it changed the values; however, I don't know if it's correct or not.  So if this doesn't work and you need more help, please post what the values in that column are supposed to be.

AVG(

        AGGR(

              SUM(CostDefaultValue1

                                    * if(ParamName2='Param A',if(/*column(4)*/

                                                                  AGGR(SUM(if(TimeParamName1='Param 1',_varParamTime1,if(TimeParamName1='Param 2',_varParamTime2,TimeDefaultValue1))+ TimeDefaultValue2

                                                                            )

                                                                        ,Level1,Level2,Level3,ParamName2) > 30

                                                                        , _varParamA_high

                                                                  , if(AGGR(SUM(if(TimeParamName1='Param 1',_varParamTime1,if(TimeParamName1='Param 2',_varParamTime2,TimeDefaultValue1))+ TimeDefaultValue2

                                                                            )

                                                                        ,Level1,Level2,Level3,ParamName2) > 20

                                                                        , _varParamA_medium

                                                                  , _varParamA)),

                                      if(ParamName2='Param B',_varParamB,

                                      if(ParamName2='Param C',_varParamC,

                                          CostDefaultValue2

                                          )))

                )  * ProbabilityValue

            ,Level1,Level2,Level3,ParamName2)

  

      

)

gopalopsharma
Creator
Creator

Hello Farwul,

Thanks for the detailed problem statement.

Can you please explain the purpose behind what are you trying to do?

What is end goal e.g. do you wish to create a chart to show the values?

It will be good to understand the problem better

Not applicable
Author

Thanks a lot Nicole!

The error was indeed in the aggr() calculations.

I followed your advice and the result is now correct 🙂

I attach to this message the qvw corrected version for information.

Not applicable
Author

Hello Gopal,

Nicole Smith's answer was right and I was able to achieve what I was looking for.

The purpose of the application is to do simulations on various processes. Each process can be divided into steps and each step can have a cost and a duration which are themselves sums of variables.

The idea is to substitute those variables by parameters that may be modified by user through slider objects for real time simulation.

The end-goal is to create charts or pivot tables that compare initial values VS user's values.