Forum Discussion
Unique Count in Row convert
Hi all,
I have issue trying to convert simple excel formula in pbi.
Sorry I wasn't transparent in my initial post (ignore the table sample below and see sample data link). I have over million row in excel model. I want to create table output that works across all various dimension based on filter.
Is it just simple dynamic measure distinct count across the row then union of selectcolumn?
Excel Formula:
Uniq Ct = IF (C2=1, " ", IF (COUNTIF($A$2:A5,A5)=1, 1, " "))
| Column A | Column B | Column C |
| Acct # | Uniq Ct | Prior Yr Uniq Ct |
| 9423 | 1 | |
9331 | 1 | |
| 8755 | 1 | |
| 5694 | 1 |
Hi Tevon713,
Thank you for the follow-up and for testing the helper-table approach.
The behaviour you are seeing occurs because Power BI measures are always evaluated based on the current filter context, so when a helper table is related back to the fact table, slicers such as Year, Region, or Product still propagate and change the result. This is why the unique count continues to vary (for example 7 instead of 14), even though the logic appears correct.
If your requirement is to count accounts that appear exactly once in the entire dataset and keep that value constant regardless of filters, the uniqueness logic must explicitly ignore report filters. You can achieve this using the following measure, which evaluates uniqueness across the full dataset and removes all filters:Truly Unique Accounts := CALCULATE ( COUNTROWS ( FILTER ( SUMMARIZE ( ALL ( 'Fact' ), 'Fact'[Acct #], "RowCnt", COUNTROWS ( 'Fact' ) ), [RowCnt] = 1 ) ), REMOVEFILTERS ( 'Fact' ) )This measure evaluates uniqueness at the Account # level and will consistently return 14, matching the intent of your original Excel logic, regardless of how the report is filtered.
Thanks again for using the Microsoft Fabric Community Forum.
22 Replies
- ryan_mayuSuper User
not clear about the formula. why it's 1 for 9331. When you drag down the excel formula, A5 will change to A6. However, A6 is blank in your sample data. Could you pls clarify this?
- cengizhanarslanSuper User
In Power BI you normally don’t create a “flag” column like Excel to then “count” later. You can get the same result more cleanly with a measure (recommended). If you truly need a calculated column that mimics your Excel helper, you can do that too.
Measure:
Unique Accts (not prior yr) = CALCULATE ( DISTINCTCOUNT ( T[Acct #] ), T[Prior Yr Uniq Ct] <> 1 )Calculated Column (if needed):
Uniq Ct (column) = VAR IsPrior = 'T'[Prior Yr Uniq Ct] = 1 VAR Acct = 'T'[Acct #] VAR FirstRowForAcct = CALCULATE ( MIN ( 'T'[RowId] ), FILTER ( 'T', 'T'[Acct #] = Acct ) ) RETURN IF ( IsPrior, BLANK(), IF ( 'T'[RowId] = FirstRowForAcct, 1, BLANK() ) )- Tevon713Helper V
Thanks cengizhanarslan now I thinking more about it if filtering across different dimension this not distinct
- danextianSuper User
Still unclear what you want to achieve. But try this:
Test measure = CALCULATE ( DISTINCTCOUNT ( 'Table'[Acct #] ), KEEPFILTERS ( 'Table'[Prior Yr Uniq Ct] <> 1 ) ) -- or ISBLANK('Table'[Prior Yr Uniq Ct])- danextianSuper User
This is unclear. What is your definition of truly unique? Using your sample pbix and with filters applied, what results do you expect adn why?
- krishnakanth240Super User
Hi Tevon713
Can you please provide some more sample data of records to work. Also just to clarify requirement is there a date column, if it is there please add it as a column in sample data of 50 records and share. Thank you!
- danextianSuper User
Hi Tevon713
I am unclear what you're trying to achieve. If those two columns exist in your data source, you can simply SUM ('table'[column]) to get their individual sums. Otherwise, please provide a workable sample data (not an image), your expected result from the same sample data and your reasoning behind. You may post a link to Excel or a sanitized copy of your PBIX stored in the cloud.
- Tevon713Helper V
Sorry I repost with sample data
- Ashish_MathurSuper User
Hi,
Cannot understand the formula logic in your Excel file. Please explain the logic in simple language.
- Tevon713Helper V
Sorry typo it suppose to lock the first cell then count and seek entire column F if there doesn't exist a count in year prior flag column H.
Ideally if I add monthly data then column H doesn't really matter if it just "distinctcounts" column F, how to keep it dynamic across different dimensions based on filter?
=IF(H2=1,"",IF(COUNTIF($F$2:F2,F2)=1,1,""))- Ashish_MathurSuper User
Still very confusing. Try this measure
Measure = calculate(distinctcount(Data[Acct #]),Data[Prior Yr Uniq Ct]<>1)