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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Justas4478
Post Prodigy
Post Prodigy

Counting number of rows in a table

Hi, I have a Store Stock Qty measure that is in Store Stock table.
I want to create another measure that would be able to count number of rows in a table including dublicates.

 

I did try to create a measure but it is returning wrong results.

Justas4478_0-1698758428100.png

Expected result should be 4573 rows of 0.
If it is possible I would like a measure to be able count number of rows regardless if table is filtered to show 0 or not.

 

Thanks.

5 REPLIES 5
speedramps
Super User
Super User

Click here to download the solution 

 

How it works ...

 

Create a maeasue ..

Products out of stock at all warehouses = 
VAR summarybyproduct = 
ADDCOLUMNS(
    VALUES(Inventory[Product]),
    "Total stock",
    CALCULATE(SUM(Inventory[Stock]))
    )

VAR productswithzero =
FILTER(summarybyproduct,[Total stock] = 0)

RETURN
COUNTROWS(productswithzero)

 

See example ..

 

Product 6, 7 and 8 are out of stock at all warehouse. So the answer is 3 products.

Product 8 is out of stock in China and UK but has stock in German. Therefore it is has stock.

 

 

speedramps_0-1698763464703.png

Thanks for the clear description of the problem with example data. I wish everyone did that!

Remember we are unpaid volunteers. So please click the thumbs up and the [accept as solution] button to leave kudos. 

One question per ticket please. If you need to extend your request then please raise a new ticket.

You will get a quicker response and each volunteer solver will get the kudos they deserve. Thank you ! 

If you quote @speedramps in your next tickets then I will then receive an automatic notification, and will be delighted to help you again.

Please now click the thumbs up and the [accept as solution] button.  Thnak you.

@speedramps 

This part of the DAX does not work for me

CALCULATE(SUM(Inventory[Stock]))
    )

Since my stock is only accessible throu provided measure. There is no column that I can use.

Thanks

In that case try this ... and substitute [yourstockmeasure] with your own measure name

 

I have answered your question, so please be polite and click the thumbs up and accept solution buttons


It it does not work then it is problem with your measure  ... but that is a different question


Products out of stock at all warehouses = 
VAR summarybyproduct = 
ADDCOLUMNS(
    VALUES(Inventory[Product]),
    "Total stock",
    CALCULATE([yourstockmeasure])
    )

VAR productswithzero =
FILTER(summarybyproduct,[Total stock] = 0)

RETURN
COUNTROWS(productswithzero)

 

 

@speedramps Hi, I got this error. I have no idea what it means since I am seeing it for the first time.

Justas4478_0-1699343752785.png

 


I have been lookign over your description of the solution again. And I think it is counting not what I am trying to count. Maybe my description of the problem confused you sorry if it did.
What I am trying to count is just total number of rows in the table. I attached this image maybe it will make it more clear.

Let me know if data sample would be helpfull.

Justas4478_1-1699344357481.png

The data that I have is using Live connection model so some of the actions are not available for me to use because of it.

Thanks

One part that I forgot to mention is that same product can exist in multiple stores at same time.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors