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
vpatel55
Kudo Commander
Kudo Commander

Row count of a measure result that meets a criteria

Hello,

 

I have created a measure called "Proposed total cost change". It works over several tables, and works well. It outputs both positive and negative values. 

 

I need a second measure that counts only the positive values in the matrix. Here is the code:

 

 

CountPositiveValues = 
COUNTROWS(
    FILTER (
        SUMMARIZE (
            AgentsImport,
            AgentsImport[Agent Name],
            "COUNT", [Proposed total cost change]
        ),
        [COUNT]>0
    )
)

 

 

However, it does not work. It seems to be counting every value, not just those above zero. I created a diagnostic table to see what is happening. It seems that rather than filtering by Agent Name, the measure is outputing the grand total for every Agent. That is why it seems to be counting every value, as they are all above zero.

 

This repeating pattern usually occurs when a table has not been linked correctly, however "Proposed total cost change" is a measure, and its relationships are already implicit, as is clear in the first matrix? So any guidance here would be great.

 

I can't easily send the source file because of confidential data. But any help on counting just the positive values would be appreciated.

 

Extract.png

Thanks.

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@vpatel55 try this

 

Positive Count = 
SUMX ( VALUES ( AgentTable[AgentName] ), IF ( [Your Measure] > 0, 1, 0 ) )

 

Would appreciate Kudos 🙂 if my solution helped.



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.

View solution in original post

4 REPLIES 4
parry2k
Super User
Super User

@vpatel55 try this

 

Positive Count = 
SUMX ( VALUES ( AgentTable[AgentName] ), IF ( [Your Measure] > 0, 1, 0 ) )

 

Would appreciate Kudos 🙂 if my solution helped.



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.

Thanks @parry2k for the quick response. I'm afraid it seems to give exactly the same output as my measure. Here is a screenshot, where your measure is "CountPositivesValues2", and mine is "CountPositivesValues1". It still seems to be counting all 377 agents.

 

However maybe we can work with this, because your measure (CountPositiveValues2) does seem to classify only those that are over zero? It's just that those that are classified, as classed as "377". So perhaps a count of nonzeros of your measure?

 

Although there may be a cleaner way of doing it? Thanks 🙂

 

Extract2.png

@vpatel55 can you share pbix file, remove sensitive information before sharing. seems like i'm missing something, it should work based on info you provided.



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've had a faceplam moment! While I was removing the sensitive information, I noticed that I have two agent tables, and I had used one agent table in the the primary measure, and the wrong agent table in the count measure! When I used the correct one, both of our solutions worked perfectly, but yours is much more elegant! Kudos to you sir 🙂

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.