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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Ahmed_Mohamed
Regular 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

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
v-cherch-msft
Employee
Employee

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.

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 

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.
jdbuchanan71
Super User
Super User

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.

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 

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



Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.