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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Create Calculated Column with Conditions

Good morning, I hope you can help me what I want to do in Power Bi in this

 

If a worker has the number 15 twice (that is, the name is repeated), how can I make a column place the number 2?

11.png

Captura de pantalla 2022-07-08 144923.jpg


If a worker has a value less than 15, give me the number 1

22.png

 

If a worker has 3 times 15, let me have the number 3

333.png

Note: All this calculation in a single column as I can do it through the DAX language

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

I think you can try this code to create a calculated column.

Calculated Column with Conditions =
VAR _COUNT_15 =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[NOMBRES] ), 'Table'[LIQ] = 15 )
    )
VAR _COUNT_Lessthan_15 =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[NOMBRES] ), 'Table'[LIQ] < 15 )
    )
RETURN
    IF ( _COUNT_Lessthan_15 = 1, 1, _COUNT_15 )

Result is as below.

RicoZhou_0-1657610655081.png

 

Best Regards,
Rico Zhou

 

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

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @Anonymous ,

 

I think you can try this code to create a calculated column.

Calculated Column with Conditions =
VAR _COUNT_15 =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[NOMBRES] ), 'Table'[LIQ] = 15 )
    )
VAR _COUNT_Lessthan_15 =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[NOMBRES] ), 'Table'[LIQ] < 15 )
    )
RETURN
    IF ( _COUNT_Lessthan_15 = 1, 1, _COUNT_15 )

Result is as below.

RicoZhou_0-1657610655081.png

 

Best Regards,
Rico Zhou

 

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

Ashish_Mathur
Super User
Super User

Hi,

See if this calculated column formula works

Count = calculate(countrows(Data),filter(Data,Data[Nombres]=earlier(Data[Nombres])&&Data[LIQ]=earlier(Data[LIQ])))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable


Good morning, is that formula to create a calculated column or a measure? I want to create a calculated column with those conditions.

Hi,

As mentioned in my earlier message, mine is a calculated column formula.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Captura de pantalla (150).pngCaptura de pantalla (151).pngCaptura de pantalla (153).png

 

Thank you very much, but the formula only prints the duplicate results, that is, if there are 2 duplicates, it gives me the number 2 or if there are 3, it gives me the number 3

 

But I want that if the number is If a name has 2 times 15, I want to put the number 2

If it is less than 15, let me put 1

 

Hi,

Try this calculated column formula

Calc = if(Data[LIQ]<15,1,if(Data[Count]=2,2,""))


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.