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
Bogdan-Ciocoiu
Regular Visitor

Count the number of rows with the PID value equal to current row's UID

Hello community -- I have a table below, and I need to calculate the last column as a custom measure/custom column. I'm grateful for any advice concerning the formulae. Please note this is a single table. The last column counts the number of rows which have as PID, the respective row's UID.

 

IDPIDCount rows
1 2
211
310
4 0
520

 

Many thanks for considering my request.

 

Best wishes,

Bogdan Ciocoiu

1 ACCEPTED SOLUTION
Bogdan-Ciocoiu
Regular Visitor

I found the answer:

 

Create a second identical SharePoint list and use the below.

 

Additional column =

    calculate (

        COUNTROWS('SharePoint list (replica)'),

        FILTER('SharePoint list (replica)','SharePoint list (replica)'[PID]='SharePoint list'[ID])

    )

 

Best wishes,

Bogdan Ciocoiu

View solution in original post

7 REPLIES 7
Bogdan-Ciocoiu
Regular Visitor

I can confirm that by creating a second Power BI data set (by loading, again, the same SP list) works.

 

Best wishes,

Bogdan Ciocoiu

Bogdan-Ciocoiu
Regular Visitor

I found the answer:

 

Create a second identical SharePoint list and use the below.

 

Additional column =

    calculate (

        COUNTROWS('SharePoint list (replica)'),

        FILTER('SharePoint list (replica)','SharePoint list (replica)'[PID]='SharePoint list'[ID])

    )

 

Best wishes,

Bogdan Ciocoiu

Anonymous
Not applicable

Step 1: Create a summarized table to fetch the count of PID

          Table 2 = SUMMARIZE('Table','Table'[PId],"COUNT",count('Table'[PId]))
 
Step 2: Join the main table to the Summarized table (Table 2) using the column "ID" (Table 2(PID) --> Main Table(ID))
 
Step 3: Create the tablular visual for ID,PID from Main table and the "count" column from the Summarised table.
 
Step 4: Enable "Show items with no data" for ID.
 
 
 
 

Hello,

Can someone confirm what the syntax would be if PID and UID were columns in the same SharePoint list, please? I think this is the key.

Count Measure =
VAR __id = MAX ( PID[ID] )
RETURN
CALCULATE (
COUNTROWS ( PID ),
ALL ( PID ),
TREATAS ( { __id }, PID[PID] )
) + 0

Bogdan-Ciocoiu
Regular Visitor

Hello Parry, thank you for your swift reply. I'm facing a few challenges due to my setup being slightly different from the one presented above. I'm using Power BI Desktop 2.83, and I'm pulling data from a SharePoint site. My columns are not titled ID and PID; for me to call them, I would have to use something like:

 

'SharePoint list name'[PID column name] instead of PID

 

When I start converting this MAX ( PID[ID] ), I get the red error market under PID(ID), and no matter how I refer to my actual column title, I can't seem to be able to get rid of the error. I tried:

 

'SharePoint list name'[PID column name] ['SharePoint list name'[ID column name] ]

 

Is there an alternative way, I might be able to pull this off, without calling this syntax: PID[ID]?

 

Thank you,

Bogdan Ciocoiu

parry2k
Super User
Super User

@Bogdan-Ciocoiu add following measure

 

 

Count Measure = 
VAR __id = MAX ( PID[ID] )
RETURN
CALCULATE (
    COUNTROWS ( PID ),
    ALL ( PID ),
    TREATAS ( { __id }, PID[PID] )
) + 0

 

 

image.png

 

 

 

Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

I think the issue is that my MAX() accepts only one column as parameter, while you're saying MAX (PID[ID]) and I don't think that PID[ID] works with SharePoint lists. Can you confirm, please how would the entire syntax look like with SharePoint lists?

 

Bogdan

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.