cancel
Showing results for
Did you mean:
Frequent Visitor

## How to build power Bi Count If Formula such as this excel formula IF(COUNTIF(P\$3:P3,P3)=1,1,"")

The idea is to remove any duplicate value and replaced by blank and then count it once for example

if I have

Raw 1               Product A

Raw 2              Product A

Raw 3              Product A

All three product in three rows I need to count 1 record and leave the other two as blank to be like this

Raw 1              Product A      =   1

Raw 2              Product A      = blank

Raw 3              Product A     = blank

Thanks and I waiting for someone to help me ...thnx a lot

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft

## Re: How to build power Bi Count If Formula such as this excel formula IF(COUNTIF(P\$3:P3,P3)=1,1,&amp

I would suggest you add an index column in sql server for the table.Then create below two columns.

```Column =
CALCULATE (
COUNT ( 'Table1'[Column1] ),
FILTER (
'Table1',
'Table1'[Column1] = EARLIER ( 'Table1'[Column1] )
&& 'Table1'[Index] <= EARLIER ( 'Table1'[Index] )
)
)
```
`Column 2 = IF(Table1[Column]=1,1,BLANK())`

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
6 REPLIES 6
Super User

## Re: How to build power Bi Count If Formula such as this excel formula IF(COUNTIF(P\$3:P3,P3)=1,1,&quo

Hello @Ahmed_Mohamed

The challenge is that in PowerBI "cell" C2 (the one with the second formula) has no idea what is in any of the other cells.

In your data, what is making the Product appear multiple times?  What is different on row 2 and 3?  We might be able to use that information along with IF and DISTINCTCOUNT to get what you need.

Frequent Visitor

## Re: How to build power Bi Count If Formula such as this excel formula IF(COUNTIF(P\$3:P3,P3)=1,1,&amp

Hello

Referring to your point@ the different in Raw 2 and Raw 3 is another needed data columns and is not duplicated for example product A includes 3 different SKUs, 3 different number of Orders, erc.. so I need to say I have 1 product include multiple items

Super User

## Re: How to build power Bi Count If Formula such as this excel formula IF(COUNTIF(P\$3:P3,P3)=1,1,&amp

@Ahmed_Mohamed If you use DISTINCTCOUNT ( table[Product] ) it will give you the correct values, even at the total level.  It won't hide the value on the additional rows but may get you close to what you are looking for and will work regardless of the additional columns in your visual.

Highlighted
Microsoft

## Re: How to build power Bi Count If Formula such as this excel formula IF(COUNTIF(P\$3:P3,P3)=1,1,&quo

You may get it in query editor as below.Please paste below formula in advanced editor to check the steps.

```let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKTylNLlFwVIrVIY7nhJ8XCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Column1"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
#"Expanded Partition" = Table.ExpandTableColumn(#"Grouped Rows", "Partition", {"Index"}, {"Partition.Index"}),
#"Added Conditional Column" = Table.AddColumn(#"Expanded Partition", "Custom", each if [Partition.Index] = 1 then 1 else null)
in

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Frequent Visitor

## Re: How to build power Bi Count If Formula such as this excel formula IF(COUNTIF(P\$3:P3,P3)=1,1,&amp

Thanks a lot for the solution by using advancer editor, but the issue in my data that I'm using a data table and I do not have permission to access the edit query as we are using SQL server datasets, so the only solution that I have to use DAX formula giving the same purpose

Is DAX formula applicable to my logical MS excel formula?

Thanks again

Microsoft

## Re: How to build power Bi Count If Formula such as this excel formula IF(COUNTIF(P\$3:P3,P3)=1,1,&amp

I would suggest you add an index column in sql server for the table.Then create below two columns.

```Column =
CALCULATE (
COUNT ( 'Table1'[Column1] ),
FILTER (
'Table1',
'Table1'[Column1] = EARLIER ( 'Table1'[Column1] )
&& 'Table1'[Index] <= EARLIER ( 'Table1'[Index] )
)
)
```
`Column 2 = IF(Table1[Column]=1,1,BLANK())`

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Announcements

#### New Kudos Given Badges Coming

We're rolling out new Kudos Given badges. Find out how many Kudos you've given.

#### November 2019 Community Highlights

Get an overview of the events and great community content from November.

#### Power Platform World Tour

Find out where you can attend!

Top Solution Authors
Top Kudoed Authors (Last 30 Days)