Planning dashboard for sales in google sheets

戏子无情 提交于 2020-05-16 21:58:31

问题


Sheet for testing:

https://docs.google.com/spreadsheets/d/1t_hjD6Yx7iv_a9tcgETf82cZbl2cdV8vd0PuTQXZP6Y/edit?usp=sharing

Objective:

I'm trying to create an automated planning sheet for one of my clients. The idea is for the sheet is to:

  • Take manual input of the total sales goal in cell B1
  • Return cost, leads, and sales broken down by advertising platform

Current Sheet Setup:

Cell B1 is the only manual input in the sheet. For the table between A4:G10, the columns highlighted in green are fixed values. The cost column B4:B10 and the sales column G4:G10 are calculated fields. The goal is to calculate the values of the leads column such that the total of the sales column in cell G10 is equal to the sales target in cell B1.

Constraints of calculating the leads from each channel:

Each advertising platform has a maximum number of leads that it can generate shown in column E4:E10. So, in this test sheet, the maximum number of leads that can be generated by Facebook is 500 and by Bing is 1000 and so on.

The advertising platforms are listed in order of increasing cost per lead shown in column C4:C10. So the channel on top is the cheapest, while the one at the bottom is the most expensive. The goal is to maximize leads from the cheapest channel first and then move on to the next channel until the sales goal is achieved. In the test sheet, we need to get 500 leads from Facebook first, then 500 leads from Google Ads, then 1000 leads from Bing, and so on till the total of sales in cell G10 is equal to the sales target in cell B1.

I'm kind of lost on this and I would appreciate any help that you can share with me!


回答1:


From what I understand reading your question is you just need help with how to calculate the leads, which is column D5:D9. And you want the total sales to be equal of the value in the cell B1. Apologies if I misunderstood your question.

Here's what you can try if I got your question right-

salesLimit = int(input())
#These are the values from the column E
leadLimit = [500,500,1000,1000,1000]
for x in range(0,len(leadLimit)):
    #Multiplying with 3/100 because it's the conv rate found in column F
    if(leadLimit[x]*3/100)<salesLimit:
        salesLimit -= leadLimit[x]*3/100
        print("D"+str(5+x)," = ",leadLimit[x]*3/100)
    else:
        print("D"+str(5+x)," = ",salesLimit)
        salesLimit = 0

Sample input for B1:

100

Output for the given input:

D5  =  15.0
D6  =  15.0
D7  =  30.0
D8  =  30.0
D9  =  10.0

Since the lead limit is already sorted in your sheet, you'll get your expected answer by doing this.




回答2:


I figured out how to do what I needed. I added a button that would trigger the script function calculate() to do the calculation. Its a very basic script and I'll post another question to figure out if it can be optimized - my actual sheet has a dynamic number of advertising platforms and I still need the script to adapt to that.

Script:

function calculate() {

  // Get the planning sheet  
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet()
  var sheet = spreadsheet.getSheetByName('Planner')

  // Get contract target as the input
  var target = sheet.getRange('B1').getValue()

  // Clear the pin cards list
  sheet.getRange('D11:D15').clearContent()

  // Set the value of the first channel
  firstChannelValue(sheet, target)

  // Set the value of the second channel
  secondChannelValue(sheet, target)

  // Set the value of the third channel
  thirdChannelValue(sheet, target)

  // Set the value of the fourth channel
  fourthChannelValue(sheet, target)

  // Set the value of the fifth channel
  fifthChannelValue(sheet, target)

}

function firstChannelValue(sheet, target) {

  // Max number of pin cards
  var pcLimit = sheet.getRange('E11').getValue()

  // Conversion rate
  var convRate = sheet.getRange('F11').getValue()

  // Cell that needs to be filled
  var pinCard = sheet.getRange('D11')

  // Max possible value
  var maxValue = pcLimit*convRate

  // Set value of cell  
  if (maxValue <= target) {  
    pinCard.setValue(pcLimit)    
  }
  else {
    pinCard.setValue(target/convRate)
  }  
}


function secondChannelValue(sheet, target) {

  // Max number of pin cards
  var pcLimit = sheet.getRange('E12').getValue()

  // Conversion rate
  var convRate = sheet.getRange('F12').getValue()

  // Cell that needs to be filled
  var pinCard = sheet.getRange('D12')

  // Max possible value
  var maxValue = (pcLimit*convRate)

  // Value of first channel contracts
  var firstChannel = sheet.getRange('G11').getValue()

  // Revised target
  var revisedTarget = target - firstChannel

  // Set value of cell  
  if (maxValue <= revisedTarget) {  
    pinCard.setValue(pcLimit)    
  }
  else {
    pinCard.setValue(revisedTarget/convRate)
  }    
}


function thirdChannelValue(sheet, target) {

  // Max number of pin cards
  var pcLimit = sheet.getRange('E13').getValue()

  // Conversion rate
  var convRate = sheet.getRange('F13').getValue()

  // Cell that needs to be filled
  var pinCard = sheet.getRange('D13')

  // Max possible value
  var maxValue = (pcLimit*convRate)

  // Value of previous channel contracts
  var firstChannel = sheet.getRange('G11').getValue()
  var secondChannel = sheet.getRange('G12').getValue()

  // Revised target
  var revisedTarget = target - firstChannel - secondChannel

  // Set value of cell  
  if (maxValue <= revisedTarget) {  
    pinCard.setValue(pcLimit)    
  }
  else {
    pinCard.setValue(revisedTarget/convRate)
  }    
}


function fourthChannelValue(sheet, target) {

  // Max number of pin cards
  var pcLimit = sheet.getRange('E14').getValue()

  // Conversion rate
  var convRate = sheet.getRange('F14').getValue()

  // Cell that needs to be filled
  var pinCard = sheet.getRange('D14')

  // Max possible value
  var maxValue = (pcLimit*convRate)

  // Value of previous channel contracts
  var firstChannel = sheet.getRange('G11').getValue()
  var secondChannel = sheet.getRange('G12').getValue()
  var thirdChannel = sheet.getRange('G13').getValue()

  // Revised target
  var revisedTarget = target - firstChannel - secondChannel - thirdChannel

  // Set value of cell  
  if (maxValue <= revisedTarget) {  
    pinCard.setValue(pcLimit)    
  }
  else {
    pinCard.setValue(revisedTarget/convRate)
  }    
}


function fifthChannelValue(sheet, target) {

  // Max number of pin cards
  var pcLimit = sheet.getRange('E15').getValue()

  // Conversion rate
  var convRate = sheet.getRange('F15').getValue()

  // Cell that needs to be filled
  var pinCard = sheet.getRange('D15')

  // Max possible value
  var maxValue = (pcLimit*convRate)

  // Value of previous channel contracts
  var firstChannel = sheet.getRange('G11').getValue()
  var secondChannel = sheet.getRange('G12').getValue()
  var thirdChannel = sheet.getRange('G13').getValue()
  var fourthChannel = sheet.getRange('G14').getValue()

  // Revised target
  var revisedTarget = target - firstChannel - secondChannel - thirdChannel - fourthChannel

  // Set value of cell  
  if (maxValue <= revisedTarget) {  
    pinCard.setValue(pcLimit)    
  }
  else {
    pinCard.setValue(revisedTarget/convRate)
  }    
}


来源:https://stackoverflow.com/questions/61483445/planning-dashboard-for-sales-in-google-sheets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!