Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
amaral_diego
Helper II
Helper II

DAX: Conditional in Calculated Column

Hi everyone,

I’m working on a calculated column in Power BI and need some help with DAX. Here is what I’m trying to achieve:

  1. I have a column called “MOTIVO” with values like “Afastamento”, “Ausência”, “Falta”, “Férias”, and “Presença”.
  2. I have another column called “CONTADOR” with values “0” and “1”.
  3. I need to create a calculated column that:
    • Shows “Cumpriu” if the value “1” appears 3 times or more in the “CONTADOR” column within the same week.
    • Shows “Não Cumpriu” if the value “1” appears less than 3 times in the “CONTADOR” column within the same week.
    • Shows “Afastamento” or “Férias” if the “MOTIVO” column has these values, regardless of the “CONTADOR” values.

Here is the DAX code I have so far:

StatusPolitica = 
VAR SemanaAtual = WEEKNUM('PRINCIPAL'[DIA], 2)
VAR SiglaAtual = 'PRINCIPAL'[SIGLA]
VAR MotivoAtual = SELECTEDVALUE('PRINCIPAL'[MOTIVO])
VAR MarcaçõesSemana = 
    CALCULATE(
        COUNTROWS('PRINCIPAL'),
        FILTER(
            'PRINCIPAL',
            WEEKNUM('PRINCIPAL'[DIA], 2) = SemanaAtual &&
            'PRINCIPAL'[SIGLA] = SiglaAtual &&
            'PRINCIPAL'[CONTADOR] = 1
        )
    )

RETURN
IF(
    MotivoAtual IN {"Afastamento", "Férias"},
    MotivoAtual,
    IF(
        MarcaçõesSemana >= 3,
        "Cumpriu",
        "Não Cumpriu"
    )
)

However, this code isn’t working as expected. It still shows “Cumpriu” or “Não Cumpriu” even when the “MOTIVO” column has “Afastamento” or “Férias”.

Could someone help me identify what I’m doing wrong or suggest a better approach?

Thank you!


Feel free to adjust the wording as needed. This should provide a clear and detailed explanation of your issue to the community. If you need any more help, let me know! 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @amaral_diego ,

 

You can try this calculation column.

StatusPolitica = 
VAR SemanaAtual = WEEKNUM('PRINCIPAL'[DIA], 2)
VAR SiglaAtual = 'PRINCIPAL'[SIGLA]
VAR MotivoAtual = 'PRINCIPAL'[MOTIVO]
VAR Marca = 
    CALCULATE(
        COUNTROWS('PRINCIPAL'),
        FILTER(
            'PRINCIPAL',
            WEEKNUM('PRINCIPAL'[DIA], 2) = SemanaAtual &&
            'PRINCIPAL'[SIGLA] = SiglaAtual &&
            'PRINCIPAL'[CONTADOR] = 1
        )
    )

RETURN
IF(
    MotivoAtual IN {"Afastamento", "Férias"},
    MotivoAtual,
    IF(
        Marca >= 3,
        "Cumpriu",
        "Não Cumpriu"
    )
)

vkaiyuemsft_0-1730339048911.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @amaral_diego ,

 

You can try this calculation column.

StatusPolitica = 
VAR SemanaAtual = WEEKNUM('PRINCIPAL'[DIA], 2)
VAR SiglaAtual = 'PRINCIPAL'[SIGLA]
VAR MotivoAtual = 'PRINCIPAL'[MOTIVO]
VAR Marca = 
    CALCULATE(
        COUNTROWS('PRINCIPAL'),
        FILTER(
            'PRINCIPAL',
            WEEKNUM('PRINCIPAL'[DIA], 2) = SemanaAtual &&
            'PRINCIPAL'[SIGLA] = SiglaAtual &&
            'PRINCIPAL'[CONTADOR] = 1
        )
    )

RETURN
IF(
    MotivoAtual IN {"Afastamento", "Férias"},
    MotivoAtual,
    IF(
        Marca >= 3,
        "Cumpriu",
        "Não Cumpriu"
    )
)

vkaiyuemsft_0-1730339048911.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

It's worked, thanks a lot!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.