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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
awsiya
Helper I
Helper I

IF(COUNTIF)

Hi PowerBI Community,

I am facing a challenge with a DAX formula. I currently have an Excel formula, which I have included screenshot below. The formula is an IF(CountIF) formula. Essentially, I have a column in Excel where some values are repeated, and I intend to display unique values as 1, but when there is a duplicate value, I want to display 0. You can see an example below.

Now, I have the same column in Power BI, and I'd like to use DAX (preferably a calculated column) to achieve the same result. I have made an attempt using differnet approached but failed..

Is there a way to achieve this in Power BI? if yes could you please guide. I have same column names in powerBI

awsiya_0-1694585778837.png

 



1 ACCEPTED SOLUTION

Hi @awsiya 
Add index column via PQ

and modify the formula to :

FirstAppearance =
VAR CurrentValue = 'table'[value]
RETURN
IF (
    CALCULATE (
        COUNTROWS ('table'),
        FILTER (
            'table',
            'table'[value] = CurrentValue
                && 'table'[Index] <= EARLIER('table'[Index])
        )
    ) = 1,
    1,
    0
)
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

4 REPLIES 4
awsiya
Helper I
Helper I

It worked. Thank you so very much. 

awsiya
Helper I
Helper I

Hi @Ritaf1983 . Thank you for giving solution. But it should show True to at least one of the duplicates. e., if I have two or three (let us assume 3) values  that are identical, it shoudl reflect at least 1 true and mark the rest of the duplicates false. If you look at my orginal excel sheet that is exactly what excel formula had done. If there is set of 2 duplicataes, it will mark one true (1) and one false (0). with the formula that you provided, it surely is giving me true for the individual values but also giving me false to all other duplicates. Please see my screenshot of excel i have explained in little more detail what I wanted. I would really apprciate if solution is provided 🙂

IFCOUNTIF.JPG

Ritaf1983
Super User
Super User

Hi @awsiya 

You can add a calculated column with the formula :

IsUnique = COUNTROWS(FILTER('Table', 'Table'[value] = EARLIER('Table'[value]))) = 1
 
**It returns true/false, so if you want 0/1 just change the datatype to "whole number"
Unfortunately, i am out of the limit of images I can add to discussions, so if you need to see the image please download it from : Here 
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Hi @awsiya 
Add index column via PQ

and modify the formula to :

FirstAppearance =
VAR CurrentValue = 'table'[value]
RETURN
IF (
    CALCULATE (
        COUNTROWS ('table'),
        FILTER (
            'table',
            'table'[value] = CurrentValue
                && 'table'[Index] <= EARLIER('table'[Index])
        )
    ) = 1,
    1,
    0
)
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon & SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

Users online (1,108)