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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Calculated column returning wrong value

Hey, im having problem with a calculated column. I have a column with ID CLIENTE (more than 50K lines) including repeated values and I need to do a new column that works with a kind of COUNTIF (returning how many times this ID appear in the column ID CLIENTE) and divide it by 1 (the max value that I can have is 1) so I did this column called "flag client" with this DAX syntax 

 
flag cliente = DIVIDE(1, CALCULATE(COUNT(BASE_BANCO2_20221223[ID CLIENTE]), BASE_BANCO2_20221223[ID CLIENTE] = BASE_BANCO2_20221223[ID CLIENTE]), 0)
 
Im getting the exact correct value doing the same thing on Excel using a 1/COUNTIF with the result = 24.424
But for Power Bi im getting the sum of the column = 25277
 
It seems the column is not working properly (returning the correct value) since I have too much data, I already fixed by using DistintCount for ID Cliente but still not what I want because I need in the decimal way to reference in others situations. Can someone help me?  
 
oshiouy_0-1672852577886.png

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Try

flag cliente =
DIVIDE (
    1,
    CALCULATE (
        COUNTROWS ( BASE_BANCO2_20221223 ),
        ALLEXCEPT ( BASE_BANCO2_20221223, BASE_BANCO2_20221223[ID CLIENTE] )
    ),
    0
)

View solution in original post

4 REPLIES 4
johnt75
Super User
Super User

Try

flag cliente =
DIVIDE (
    1,
    CALCULATE (
        COUNTROWS ( BASE_BANCO2_20221223 ),
        ALLEXCEPT ( BASE_BANCO2_20221223, BASE_BANCO2_20221223[ID CLIENTE] )
    ),
    0
)
Anonymous
Not applicable

It worked!! but why can you explain what's the point of using countrows and using allexcept? 

COUNTROWS is just a bit more optimised I think, so I tend to use that rather than COUNT.

The real key is the ALLEXCEPT. When you are creating a calculated column every column in the table is part of the filter, ALLEXCEPT removes the extra columns and you can just keep the columns that you need to be in the filter. This also helps to avoid circular dependency errors if you add multiple calculated columns to the same table.

Anonymous
Not applicable

Thanks for the solution and explanation!!

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.