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
Bart-ek
Helper I
Helper I

count number of visible rows with specific product

Hi

 

I'm getting troubles to figure out how to get a column with number of visible lines with specific product.

(visible lines because at that moment slicers already filtered big list with dates, countries etc.)

 

I'd like to achieve in the matrix is something like this (yellow collumn is the one that I'm missing):

 

image.png

 

critical is to keep mutliple lines not cumulative view (which would be simplier)

 

I've tried:

  • calculated column but it always gives me the same amount as allselected doesn't work on it,
  • calcualted measure, but I could only get:
    • count of all visible cells when used allselected (as earlier couldn't work for me)
    • or value 1 in each cell, as for every row there's just 1 line with the same sales product.

 

Does anybody has an idea how to get that calculated additional column in the matrix (assuming that number needs to change depending on selection criteria/visible product lines)?

9 REPLIES 9
Bart-ek
Helper I
Helper I

I think I've figured it out with a measure... I'm still checking if results are correct but looks fine. If you see any mistake in a logic please let me know.

 

repeat = CALCULATE(
    COUNTROWS('table'),
    FILTER(ALLSELECTED('table'),
    IF(
        COUNTX(FILTER('table', EARLIER('table'[product]) = 'table'[product]),'table'[product]
        ) > 0, true, false)
    )
)

 

@Bart-ek seems like very complex measure for a simple count of rows. Why not sure sample data with the expected output, should be super simple.



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.

Hi,

 

I've tried with count of rows but I've failed...

  • when used in calculated column it always shows the same number, doesn't matter how I filter final matrix with dates etc.
  • when used in measure, it always show 1 (as this matrix shows lines 1 by 1 without any aggregation), or all rows visible when used with "allselected" (unless I do this method with"earlier' and "countx" which can go back and check product id).

If you know how to do it simplier please let me know, because I also think it should be much simplier than I did.

Hi @Bart-ek ,

 

This should work.

 

CALCULATE(COUNTROWS('TABLE'),ALLEXCEPT('TABLE','TABLE'[Sales Product])).
 
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!!

Hi @Bart-ek ,

 

Not sure why this is not working in your .pbix file.

 

Tried to replicate it at my end and it seems to work fine.

 

 

1.jpg2.JPG3.JPG

 

Measure 5 = CALCULATE(COUNTROWS('Table 2'),ALLEXCEPT('Table 2','Table 2'[Sales Product]))
 
Can you share your .pbix file or some sample data.
 
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!!

your example:

Measure 5 = CALCULATE(COUNTROWS('Table 2'),ALLEXCEPT('Table 2','Table 2'[Sales Product]))

 

works in your example because you filter only by product, try to filter by the date and  you'll see that number does not change even products are displayed less times.

 

I have a lot of filters by quantity, date etc. and I don't want to count all lines of product in the whole table, only already filtered lines needs to be counted.

Unfortunatelly it shows me incorrect results, for now only my solution works.

@Bart-ek 

 

You may simply use the measure below.

Measure =
CALCULATE ( DISTINCTCOUNT ( 'Table'[date] ), ALLSELECTED ( 'Table'[date] ) )

 

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,

 

this shows 1 next to every line, you need to remember that I have individual values shown with every line, they're very often for the same product. I want to count how many lines are visible for the product, but because there's no more lines in the background of 1 visible line it will show 1. Such measures that will not use ALLSELECTED will always show me only 1. That would show correct number if I'd have cumulative table.

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.