Tag: queries

  • 17. How to use conditional functions COUNTIF, SUMIF, AVERAGEIF, and MAXIFS in Excel and Google Sheets

    #conditonalfunctions #COUNTIF #SUMIF #AVERAGEIF #MAXIFS #Excel #GoogleSheets

    Conditional functions perform a specific task, but only on cells that satisfy some defined criteria. They are frequently used when constructing more complex queries.

    Assume you have the following sales dataset in A1:E11

    1️⃣ COUNTIF

    Objective:

    Count how many sales were made in the South region.

    Excel:

    =COUNTIF(C2:C11; “South”)

    Explanation:

    • C2:C11 → range to evaluate
    • “South” → criterion

    This counts all rows where Region = South.

    The same in Google Sheets

    =COUNTIF(C2:C11;”South”)

    2️⃣ SUMIF

    Objective:

    Calculate total revenue generated by Alice.

    =SUMIF(B2:B11;”Alice”;E2:E11)

    Explanation:

    • B2:B11 → criteria range
    • “Alice” → condition
    • E2:E11 → sum range

    This adds revenue only where Salesperson = Alice.

    3️⃣ AVERAGEIF

    Objective:

    Find the average revenue for Laptop sales.

    =AVERAGEIF(D2:D11;”Laptop”;E2:E11)

    Explanation:

    • D2:D11 → criteria range
    • “Laptop” → condition
    • E2:E11 → average range

    Returns the average revenue of all Laptop transactions.

    4️⃣ MAXIFS

    Objective:

    Find the maximum revenue generated in the North region by Alice.

    =MAXIFS(E2:E11;B2:B11;”Alice”;C2:C11;”North”)

    Explanation:

    • E2:E11 → max range
    • B2:B11, “Alice” → first condition
    • C2:C11, “North” → second condition

    Returns the highest single revenue value where both conditions are met = 1300.

  • 4. How to write a simple SQL Query in Big Query

    #SQL #queries #BigQuery

    Starting from the custom table I created here, click on Query:

    Start writing your query from this pane

    Question: Which are the Top 5 Most Common male Birth Names in Italy in 1999?

    In SQL pane write:

    SELECT

      nome,

      nati

    FROM `nasciteitalia.datinasciteItalia.diffusionenomi`

    WHERE

      anno=1999

    ORDER BY

      nati DESC

    LIMIT

      5

    This query selects from the data table ‘diffusionenomi’ in database ‘datinasciteItalia’ in project ‘nasciteitalia’ the  two columns (‘nome’ and ‘nati’) for the year ‘1999’ and sorts these two columns in descending order limiting the results to 5 items.

    Click RUN to see the results:

    Check with the reference table from Istat: