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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
JohnSonn
Frequent Visitor

Count all values in table that share same value as current row in pivot table

 

 

I have a duplication key and I want to see how many time this key shows up in the rest of the table.

 

Duplication key:

=CONCATENATE(CONCATENATE([Total Weight kg],"-"),[Total Net Value])

 

Key Count:

=COUNTAX(ALL('Invoice Data'),CONCATENATE(CONCATENATE([Total Weight kg],"-"),[Total Net Value])=[Duplication Check Key])

 

But at the moment I am getting this:

 

410.556-011912
3702.224-011912
869.4-011912
408.29-011912
1356.356-011912
361.496-011912
1773.014-011912
1240.89-011912

 

If I do the same thing without the ALL function:

 

=COUNTAX('Invoice Data',CONCATENATE(CONCATENATE([Total Weight kg],"-"),[Total Net Value])=[Duplication Check Key])

 

I only count items in the current row and I count all of them.

 

The difficulty is that you cannot simply use "@"[column] like you can in an excel table. Please someone help

1 ACCEPTED SOLUTION

 have found a solution to this.

 

Step 1)

Go into main table query, remove any errors from the net value column (optional)

 

Create key from relevant columns

 

Close and load (to data model)

 

Step 2)

Duplicate this query

 

Use group by to get a row count using the key as the group category.

 

Close and load (to data model)

 

Build a relationship with the original table

 

Step 3) Use related to get the count column in order to use a 'downstream' variable in any Power Pivot Table (optional)

 

 

Thanks for your support peeps!

View solution in original post

12 REPLIES 12
mahoneypat
Microsoft Employee
Microsoft Employee

If Duplication Key is an existing calculated column, why not just make a table visual with Duplication Key and the following measure? 

 

RowCount = countrows('Invoice Data')

 

If the count of rows with same Duplication Key is needed in a calculated column, you could use the following:

 

RowCount = var currentDupKey = [Duplication Key]

return calculate(countrows('Invoice Data'), all('Invoice Data'), 'Invoice Data'[Duplication Key] = currentDupKey)

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@sjoerdvn this still does not work, it reads all of the rows as before.

 

@mahoneypat  how does the currentDupKey part work? That is what I am trying to achieve.

I could do this using M code in the query editor.

 

Does anyone know how I could do this?

 have found a solution to this.

 

Step 1)

Go into main table query, remove any errors from the net value column (optional)

 

Create key from relevant columns

 

Close and load (to data model)

 

Step 2)

Duplicate this query

 

Use group by to get a row count using the key as the group category.

 

Close and load (to data model)

 

Build a relationship with the original table

 

Step 3) Use related to get the count column in order to use a 'downstream' variable in any Power Pivot Table (optional)

 

 

Thanks for your support peeps!

Glad you figured it out.  You could also do a merge in query editor and bring your count into the first table there, and then diable load on that query so you don't have that extra table in your model.

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thats great advice, thanks Pat

Great thanks for the tip!

Anonymous
Not applicable

Again.... Why are you not doing this in Power Query, where such calculations belong?

Best
D
sjoerdvn
Super User
Super User

try:

=COUNTROWS(CALCULATETABLE(ALL('Invoice Data'),VALUES([Total Weight kg]), VALUES([Total Net Value])))

 

@sjoerdvn Unfortunately this does not work. It seems to be iterating weight and net value so it counts everything

 

@Anonymous I am trying both in Power Pivot and in the data model in Power Query

So, is [Duplication Check Key] a measure or a computed column ?

What are the required output columns of your report ?

 

Anyway, I've done a little test. Assuming the [Key] column is in the required output, you could use:

= COUNTROWS(CALCULATETABLE('Invoice Data',ALL('Invoice Data'),VALUES('Invoice Data'[Total Net Value]),VALUES('Invoice Data'[Total Weight kg])))
nandukrishnavs
Super User
Super User

@JohnSonn 

 

Did you check DISTINCTCOUNT() of Duplication key?


Regards,
Nandu Krishna

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.