- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Try
flag cliente =
DIVIDE (
1,
CALCULATE (
COUNTROWS ( BASE_BANCO2_20221223 ),
ALLEXCEPT ( BASE_BANCO2_20221223, BASE_BANCO2_20221223[ID CLIENTE] )
),
0
)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Try
flag cliente =
DIVIDE (
1,
CALCULATE (
COUNTROWS ( BASE_BANCO2_20221223 ),
ALLEXCEPT ( BASE_BANCO2_20221223, BASE_BANCO2_20221223[ID CLIENTE] )
),
0
)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

It worked!! but why can you explain what's the point of using countrows and using allexcept?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Thanks for the solution and explanation!!

Helpful resources
Subject | Author | Posted | |
---|---|---|---|
07-03-2024 06:34 AM | |||
06-13-2024 06:49 PM | |||
Anonymous
| 04-02-2024 08:11 AM | ||
01-31-2024 01:11 PM | |||
09-12-2024 05:30 PM |
User | Count |
---|---|
102 | |
84 | |
81 | |
53 | |
46 |