cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ahmed_Mohamed Frequent Visitor
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 

 

Capture.PNG

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-cherch-msft Super Contributor
Super Contributor

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

Hi @Ahmed_Mohamed 

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())

a1.png

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.

View solution in original post

6 REPLIES 6
Super User
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.

Ahmed_Mohamed Frequent Visitor
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 jdbuchanan71

 

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



v-cherch-msft Super Contributor
Super Contributor

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

Hi @Ahmed_Mohamed 

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
    #"Added Conditional Column"

a1.png

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.
Ahmed_Mohamed Frequent Visitor
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

Hi @v-cherch-msft 

 

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 

v-cherch-msft Super Contributor
Super Contributor

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

Hi @Ahmed_Mohamed 

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())

a1.png

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.

View solution in original post

Helpful resources

Announcements
Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Ask Amanda Anything Q&A

Ask Amanda Anything Q&A

Learn the answers to some of the questions asked during the Amanda Triple A event.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Users Online
Currently online: 6 members 2,445 guests
Please welcome our newest community members: