Forum Discussion

HenriqueQuintela's avatar
HenriqueQuintela
Occasional Reader
Dec 23, 2025

Using mode with several criteria

Hello everyone!

I'm currently treating some data before I send it to do some machine learning.

 

I have the following data:

idAnomêsdata_inversadia_semanahorarioufbrkmmunicipiocausa_acidentetipo_acidenteclassificacao_acidentefase_diasentido_viacondicao_metereologicatipo_pistatracado_viauso_soloanopessoasmortosferidos_levesferidos_gravesilesosignoradosferidosveiculos

And I created a new table to summarize this data for months instead of accidents, here are the columns:

BR

KMAnoMêsClima (Moda)Tipo PistaAcidentesVeículosIlesosFeridos LevesFeridos GravesMortesCausa (Moda)Risco

What I want to do is calculate the mode of condicao_metereologica for each combination of BR, KM, Ano and Mês.

 

But I can't wrap my head around on how I could do this. Any help is appreciated! Let me know if I made anything not as clear as it is in my head xD

1 Reply

  • NikolinoDE's avatar
    NikolinoDE
    Platinum Contributor

    You’re essentially trying to calculate a mode with multiple criteria, which Excel doesn’t offer as a single built-in function — but there are clean and reliable ways to do it in Excel 365.

    Here is the simplest way without VBA and Office Script.

     

    BEST PRACTICE (Excel 365): FILTER + MODE.MULT

    Since you’re on Office 365, you already have all the tools you need.

    Concept

    For each row in your monthly summary table, you:

    1. Filter the original accident table by:

    • BR
    • KM
    • Ano
    • Mês

    2. Calculate the mode of condicao_metereologica from the filtered rows.

    Example structure

    Assume your raw data table is named tblAcidentes and has columns:

    • BR, KM, Ano, mes, condicao_metereologica

    And your summary table row contains:

    • [@BR], [@KM], [@Ano], [@Mês]

     

    Formula (most common case: one mode)

    =LET(

    dados, FILTER(

            tblAcidentes[condicao_metereologica],

            (tblAcidentes[BR]=[@BR]) *

            (tblAcidentes[KM]=[@KM]) *

            (tblAcidentes[Ano]=[@Ano]) *

            (tblAcidentes[mes]=[@Mês])),

        INDEX(MODE.MULT(dados),1))

     

    My answers are voluntary and without guarantee!

     

    Hope this will help you.

     

    Was the answer useful? Mark as best response and like it!

    This will help all forum participants.

Resources