Message-ID: <295334040.11.1582870021387.JavaMail.root@www> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_10_642077745.1582870021387" ------=_Part_10_642077745.1582870021387 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Calculate revenue using unit price times quantity and revenue pe= rcentage

# Calculate revenue using unit price times quantity and revenue perce= ntage

There are times that the data set only contains the unit price a= nd sold quantity without the calculated revenue. This tutorial will show yo= u how to calculate the revenue and revenue percentage towards total revenue= .

=20
=20 Icon=20
=20

It is recommended to get familiar with memberSum function before proceed= ing with this tutorial.

=20
=20
=20

The table we are going to build will have two drill down levels, Product Group and Product Name. Here is how the = table will look like.

=20
=20 =20
=20
=20 Icon=20
=20

Make sure you are displaying the Unit Price correctly. = The members aggregation should be Average rather than Sum.

=20
=20
=20

The Revenue, which equals to Unit Price times Quantity is calculated using membersSum,

=20
=20
```int totalRevenue =3D 0;

int thisRevenue =3D M_QUANTITY * M_USUAL_PRICE@AVG;
totalRevenue =3D totalRevenue + thisRevenue;    =20
}

```
=20
=20

Make sure you place the order of the drill down levels in the parameters= of membersSum correctly. It should follow the order of the drill downs in = the table, so Product Group first and then Product= Name. The last drill down level Transaction ID w= ill make sure it aggregates total revenue for all transactions belongs to t= he same product group and same product.

=20

In order to calculate the revenue percentage, we need to calculate the t= otal revenue first.

=20
=20
```aggregatePrevLevel(2){=20
int totalRevenue =3D 0;

int thisRevenue =3D M_QUANTITY * M_USUAL_PRICE@AVG;
totalRevenue =3D totalRevenue  +  thisRevenue;    =20
}

}
```
=20
=20

So the code for calculating the revenue percentage is as below:

=20
=20
```int total =3D aggregatePrevLevel(2){=20

int totalRevenue =3D 0;

=09int thisRevenue =3D M_QUANTITY * M_USUAL_PRICE@AVG;
totalRevenue =3D totalRevenue  +  thisRevenue;    =20
}

}

int totalRevenue =3D 0;