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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
MCFH93
Contributor III
Contributor III

Calculate Total For 2 Rows in Another Row in Pivot Table

Hi, I would like to display the total for F and G in H row as shown below. Below are the dimensions and expressions used in the pivot table. Can advise on how can I achieve this. Thank you.

Current Pivot Table

MCFH93_0-1720600129117.png

 

Expected Pivot Table

MCFH93_1-1720600146796.png

 

Dimension for Pivot Table

(1) SM2_SOURCE

(2) =IF(DATE(YEAREND(DATE(SM2_DATE, 'DD/MM/YYYY'), 0, 4), 'YYYY') >= YEARSTART(TODAY(), -2, 4), 'FY ' & DATE(YEAREND(DATE(SM2_DATE, 'DD/MM/YYYY'), 0, 4), 'YYYY'))

 

Expression for Pivot Table

(1) tCO₂e = SUM(AGGR(IF(SUM(SM2_VALUE) > 0, (SUM(SM2_VALUE) * SM2_CONVERSION_FACTOR) / 1000), SM2_SOURCE, SM2_DATE))

(2) MWh = ROUND(SUM(SM2_VALUE) / 1000)

 

Labels (2)
1 Reply
marcus_sommer
MVP
MVP

You may just query the source and using there the wanted calculation, like:

if(Source = 'x', Expr1, if(Source = 'y', Expr2, ..., ExprX))

Beside this you could add some upper dimension-level and then using their partial sums and/or a query on the dimensionality() to branch within different calculations.

Independent from this I suggest to replace the calculated date-dimension with native fields from an appropriate calendar and also the check if the calculation of tCO₂e  requires really an aggr() and an if-loop.