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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
MP_123
Microsoft Employee
Microsoft Employee

count if

Capture.PNG

hi, please see this table.

i want to add new measure that count for each row in the table if there are another row with the same : target date, market. etc.. (not all the columns) meaning, not if there are exact the same row, but almost.

in SQL i would join twice the same table and compare a.target date = b. target date

i can't write in in the query since i want it to calculate dynamically across slicers.

 

is someone please have an idea??

 thanks a lot!

1 ACCEPTED SOLUTION

@MP_123

 

Please try with following MEASURE formula. It should also work when you slice it.

 

Same_Row_Count = 
CALCULATE (
    COUNTROWS ( Table1 ),
    FILTER (
        ALLSELECTED ( Table1 ),
        SUMX (
            FILTER (
                Table1,
                EARLIER ( Table1[target date] ) = Table1[target date]
                    && EARLIER ( Table1[signal name] ) = Table1[signal name]
                    && EARLIER ( Table1[device] ) = Table1[device]
                    && EARLIER ( Table1[Count of Users] ) = Table1[Count of Users]
            ),
            Table1[Num]
        )
    )
)

count if_1.jpgcount if_2.jpg

 

Best Regards,

Herbert

View solution in original post

9 REPLIES 9
mtgm
New Member

Hello 🙂

 

I did an online questionnaire and I have a few questions with more than one answer.
For example:
Drink; Eat; Sleep
Eat
Drink; Sleep, Dress

So, I want to count how many times each word appears.
In excel I use countif. In case you want to know how many times the word "Drink" appears: COUNTIF (TABLE; "DRINK")

How can I do this in PowerBI?
Thanks 🙂

ankitpatira
Community Champion
Community Champion

@MP_123 If you go to power bi desktop query editor -> you get option to keep or remove duplicates and you can highlight columns for which you want to keep / remove duplicates.

hi @ankitpatira!

thanks for replying.

i don't want to keep or remove, i want to count rows, according to specific columns.

count if date=date, device= device, etc.

hope it's clear now

 

thanks!

@MP_123 You can do something like below,

 

1. Create calculated column for each column you want to find duplicates for. This will give 1 if unique and 0 if duplicate.

 

duplicateColumn1 = IF(
CALCULATE(
COUNTA(TABLE[column]),
FILTER(TABLE, TALBE[column] = EARLIER(TABLE[column]))
)>1,
0,
1
)

 

2. Then use table visual and filter out 1's which will give you count of duplicate rows.

@ankitpatira thank you

 

i tried this calculated column:

Column =
CALCULATE(COUNTROWS(' Test_Table2'),
FILTER(' Test_Table2',
' Test_Table2'[target date]=EARLIER(' Test_Table2'[target date]) &&
' Test_Table2'[signal name]=EARLIER(' Test_Table2'[signal name]) &&
' Test_Table2'[device]=EARLIER(' Test_Table2'[device]) &&
' Test_Table2'[Count of Users]=EARLIER(' Test_Table2'[Count of Users])
)
)

 

but i see that the column isn't changing dynamically. is it make sense? the values are constant no matter how i slice it.

 

regarding your solution: i think it won't work since i want to compare whole combination, and not only one at a time

 

thanks again

@MP_123

 

Please try with following MEASURE formula. It should also work when you slice it.

 

Same_Row_Count = 
CALCULATE (
    COUNTROWS ( Table1 ),
    FILTER (
        ALLSELECTED ( Table1 ),
        SUMX (
            FILTER (
                Table1,
                EARLIER ( Table1[target date] ) = Table1[target date]
                    && EARLIER ( Table1[signal name] ) = Table1[signal name]
                    && EARLIER ( Table1[device] ) = Table1[device]
                    && EARLIER ( Table1[Count of Users] ) = Table1[Count of Users]
            ),
            Table1[Num]
        )
    )
)

count if_1.jpgcount if_2.jpg

 

Best Regards,

Herbert

 

hi @v-haibl-msft

 

can you please help me understand the formula you suggest? i don't understand the use of all these functions.

 

thanks a lot!

 

@MP_123

 

Since you want to the result can change dynamically, we need to use measure here. To count the almost same rows, we need to use EARLIER function. I’d like to recommend this article to you for the principle of EARLIER function. However EARILER is usually used in column but not measure. So we need to some changes according to this article. I think it will be enlightened after you read through these two articles.

 

Best Regards,

Herbert

thanks @v-haibl-msft!

you're awsome!!!

 

but one question - i want to calculate for each row in the table the count of users \ new measure

and then to sum it all.

the divide (sum(Count),new measure) isn't the correct result

do you have an idea?

 

thanks a lot!!

Helpful resources

Announcements
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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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