Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Venancioe
Contributor
Contributor

Percentage Variance on Table

In my situation I have a line in which each column represents the revenue of each day for a product, I want to obtain the variance in percentage. For example, In the total revenue of products for those days, I want to know what is the percentage of each day in the total sum.

Ex: Total sum of DATE revenue for the days is 100, and for each day I have values like 20, 40, 10, 30. I need to know what is the percentage of each of these values in the total sum of each product

Screenshot_1.png

 

Labels (3)
3 Solutions

Accepted Solutions
NageshSG
Partner - Contributor III
Partner - Contributor III

Hi @Venancioe 

Suggesting 2 possible solutions. (used some sample data manually from your screen shot. would have helped if you had shared the data sample file!)

1. Get the next day revenue as an additional field in the script, then use it for calculation of var percentage in the front end.

2. Alternative use "Above" function but you need to switch Date as rows and Product as columns for this to work.

I have attached the qvw file with both options for your review. See the screen shot below.

NageshSG_0-1629650005838.png

Regards.

View solution in original post

NageshSG
Partner - Contributor III
Partner - Contributor III

Hi @Venancioe 

Please see attached qvf file.

Please note the script logic is the same except for the connection strings.

Make sure to change the connection strings to your local folder location and update the variable 'vsampledata' before you trigger the reload.

Regards.

View solution in original post

NageshSG
Partner - Contributor III
Partner - Contributor III

Hi @Venancioe 

Two ways of calculating the "NextDateRevenue".

1. In the front end i have used 'Above' function in the chart but has limitations.

2. Script side >> by creating an additional calculated column using the "Previous" function which evaluates the previous record value against the current record value. Make sure the table is sorted in the correct order for this to work ie. Date descending within each Product (ie. sorted by Product first). This way Previous record will always have Date which is cur record date + 1 for each Product. See the screen shot below how i used it in the script.

NageshSG_0-1629884526245.png

Hope this helps.

Regards.

View solution in original post

24 Replies
stevejoyce
Specialist II
Specialist II

Your denominator would be Sum(TOTAL <PRODUCT>} Revenue) .

Obviously your existing revenue calculation is the numerator.

Venancioe
Contributor
Contributor
Author

Hi Stevejoyce

 

Is not working as expected, it showing the same values for entire table

Screenshot_2.png

 

 

tincholiver
Creator III
Creator III

TRY THIS

 

SUM(REVENUE)
/
Aggr(NODISTINCT SUM(REVENUE),DATE)

Venancioe
Contributor
Contributor
Author

thanks Tincholiver

Its working, but I think is comparing on the vertical(complete column) for the current date.

What I want is to compare the product revenue of Previous day with product revenue of Next day and so on

Like: AIRTIME ADVANCE

Compare revenue of 8/3/2021 with  8/4/2021 ,

8/4/2021 with  8/5/2021  and so onScreenshot_3.png

Kushal_Chawda

@Venancioe  share sample data with expected output

Venancioe
Contributor
Contributor
Author

Screenshot_4.png

 

Hi @Kushal_Chawda  

Find here the sample. I want something like this one marked with red

Kushal_Chawda

@Venancioe  how % calculated? 

stevejoyce
Specialist II
Specialist II

Your initial calculation you said "percentage of each of these values in the total sum of each product".  This sounds like a different calculation no? 

You can use before/after to calculate referencing other columns

like sum(expression) - before(sum(expression)) -> difference between today's date and previous date.

tincholiver
Creator III
Creator III

I agree with Steve Joyce, you are not looking for how much each bundle represents over the total percentage, you need to know how much it changed compared to the previous day. For that you will have to calculate the following:

1. SUM ({<DATE = {'$ (= max (DATE))'}>} REVENUE) this is the last registered value

2.SUM ({<DATE = {'$ (= Date (max (DATE) -1))'}>} REVENUE) this is the value of the previous day

3.(SUM ({<DATE = {'$ (= max (DATE))'}>} REVENUE) / SUM ({<DATE = {'$ (= Date (max (DATE) -1))'}>} REVENUE))-1

this is the percentage difference you are looking for.

Take the date dimension from the graph and generate each expression per day that you need, you can do it for the last 30 days or something like that.
If you show us how the data is loaded in the table, maybe another solution can be applied

something like this:

tincholiver_1-1629461824095.png