如何结合ARRAYFORMULA和COUNTIF

时间:2019-08-02 02:38:29

标签: if-statement google-sheets google-sheets-formula countif array-formulas

我是Google表格的新手。 我尝试使用ArrayFormula和CountIf对A列中的值进行计数,但结果不是我想要的。

我尝试用这一行

const chai = require('chai')
const chaiHttp = require('chai-http')
const expect = chai.expect
chai.use(chaiHttp)

const main = require('../app')

let server  

describe('Bitmex Bot Management API - POSITION', () => {
    before(async () => {
      const app = await main()
      server = app.listen(3001)
    })

    //Price
    describe('/price/now', async () => {
      var symbol = "eth"
      //var wrongSymbol = "luc"

      describe('With a valid paramater', () => {
        var res

        before(async () => {
          res = await chai
            .request(server)
            .post('/price/now')
            .set('content-type', 'application/json')
            .send({ symbol: symbol })
        })

        it('Should have status 200', () => {
          expect(res).to.have.status(200)
        })

        it('Should return the winery wallet address attribute', () => {
          expect(res.body).to.have.nested.property('data.timestamp')
          expect(res.body).to.have.nested.property('data.symbol')
          expect(res.body).to.have.nested.property('data.side')
          expect(res.body).to.have.nested.property('data.size')        
          expect(res.body).to.have.nested.property('data.price')
          expect(res.body).to.have.nested.property('data.tickDirection')
          expect(res.body).to.have.nested.property('data.trdMatchID')
          expect(res.body).to.have.nested.property('data.grossValue')
          expect(res.body).to.have.nested.property('data.tickDirection')
          expect(res.body).to.have.nested.property('data.homeNotional')
          expect(res.body).to.have.nested.property('data.foreignNotional')
        })
      })
    })
    after(() => {
      server.close()
    })
  })

因此每行将对A2中的值进行计数,直到该行出现为止。

但是如果我尝试使用arrayformula,结果会有所不同

=COUNTIF($A$2:A2,A2)

Screenshot of result

这是my spreadsheets

请帮助我

1 个答案:

答案 0 :(得分:1)

=ARRAYFORMULA(IF(LEN(A2:A), COUNTIFS(A2:A, A2:A, ROW(A2:A), "<="&ROW(A2:A)), ))

0