COUNT, COUNTA, DISTINCTCOUNT and COUNTROWS in DAX
COUNT, COUNTA, COUNTROWS and DISTINCTCOUNT are not four names for the same total — each one answers a different grain, and blanks move the result.
Friends! “How many orders?” is where beginner measures quietly lie. Why? A line and an order are not the same row. How? We count a fictional FreshBasket Sales table four ways, then look at blank delivery minutes. Say the grain out loud before you pick the function.
मित्रांनो! “किती orders?” या प्रश्नावर नव्या measures शांतपणे खोटे बोलतात. का? एक line आणि एक order तोच row नसतो. कसे? FreshBasket च्या Sales table ला चार प्रकारे मोजायचे, मग रिकामा delivery वेळ बघायचा. function निवडण्याआधी grain मोठ्याने सांगा.
मित्रों! “कितने orders?” इस सवाल पर नए measures चुपचाप झूठ बोलते हैं. क्यों? एक line और एक order वही row नहीं होता. कैसे? FreshBasket की Sales table को चार तरीकों से गिनो, फिर खाली delivery समय देखो. function चुनने से पहले grain ज़ोर से बोलो.
Quick answer
Vertical choice:
- Rows in a table →
COUNTROWS. - Non-blank numbers in a column →
COUNT. - Non-blank values of any type →
COUNTA. - Unique values →
DISTINCTCOUNT. - Blanks themselves →
COUNTBLANK. - One order with five lines is five rows and one Order ID.
Orders = DISTINCTCOUNT ( Sales[Order ID] )
Lines = COUNTROWS ( Sales )
Why each count, why FILTER, what comes out
Same three Pune rows:
| Order ID | City | Amount | Channel |
|---|---|---|---|
| A | Pune | 100 | Online |
| A | Pune | 40 | Online |
| B | Pune | 60 | Store |
Why you pick one function:
COUNTROWS ( Sales )answers "how many lines are in the filter?" Result: 3.DISTINCTCOUNT ( Sales[Order ID] )answers "how many orders?" Result: 2. Order A is one order with two lines.COUNT ( Sales[Amount] )answers "how many numeric amounts are filled?" Result: 3, because none are blank.COUNTA ( Sales[Channel] )answers "how many channel cells are not blank?" Result: 3. Use this when the column is text.- If Amount on the middle row is blank,
COUNTbecomes 2 andCOUNTBLANKbecomes 1.COUNTROWSstays 3. The row is still there.
Why FILTER shows up with a count:
COUNTROWS ( Sales )counts every row the slicer left. It does not apply a second test.- "How many lines are above 50?" needs a test.
FILTERkeeps rows.COUNTROWSturns the kept rows into one number. - Rows in: 3. Test: Amount > 50. Rows kept: 100 and 60. Number out: 2.
DISTINCTCOUNTdoes not needFILTERwhen you only want unique IDs on the rows you already have.- Do not
FILTERthe whole Sales table just to say Channel = Online. A column filter insideCALCULATEis the lighter way. UseFILTERwhen the test is a measure, or a rule a simple column filter cannot say.
What you should say before you write it: lines, filled cells, or unique orders. Then the function is obvious.
Real example: slips, orders, and a missing phone bill
Same FreshBasket counters. In Mumbai this week the book looks like this:
| Order ID | City | Line | Amount |
|---|---|---|---|
| M-1 | Mumbai | Rice | 500 |
| M-1 | Mumbai | Oil | 200 |
| M-2 | Mumbai | Atta | 300 |
Why the count changes with the question:
- Rows in: 3 lines.
COUNTROWSout: 3. That is slips, not customers. DISTINCTCOUNTof Order ID out: 2. M-1 is one order with two lines. The owner did not get three orders.COUNTof Amount out: 3, because every amount is filled.- Now the phone bill book for the Mumbai shop: Jan 499, Feb is still blank because nobody typed it, Mar 699. Rows in: 3.
COUNTof the bill amount out: 2.COUNTBLANKout: 1.COUNTROWSstays 3. The blank month is still a row.
Why FILTER: "how many Mumbai lines are above 250?" FILTER keeps rice 500 and atta 300. COUNTROWS out: 2. Oil 200 is gone. You did not need FILTER to count all lines. You need it when there is a second test on top of the city slicer.
Click Pune and repeat the sentence out loud before you trust the card: lines, orders, or blank bills.
What do I need before this guide?
- Measures vs calculated columns.
- SUM vs SUMX so “aggregate a column” already feels normal.
- Course: Aggregation functions.
Before and after (look at the tables first)
Before
आधी (Before)
पहले (Before)
After
नंतर (After)
बाद में (After)
The FreshBasket table (fictional)
Picture five rows:
- Order A, two lines, both with delivery minutes.
- Order B, three lines, one delivery minute blank.
- That is 5 rows, 2 orders, 4 numeric delivery times, 1 blank.
Five order lines can be one order: COUNTROWS sees lines; DISTINCTCOUNT sees the Order ID.
पाच lines एकच order असू शकतात: COUNTROWS lines बघतो; DISTINCTCOUNT Order ID बघतो.
पाँच lines एक ही order हो सकती हैं: COUNTROWS lines देखता है; DISTINCTCOUNT Order ID देखता है.
If the card says 5 and the manager asked for orders, the measure used the wrong function. The visual is innocent.
The four functions, side by side
Order Lines = COUNTROWS ( Sales )
Orders = DISTINCTCOUNT ( Sales[Order ID] )
Times Filled = COUNT ( Sales[Delivery Mins] )
Channels Filled = COUNTA ( Sales[Channel] )
Times Missing = COUNTBLANK ( Sales[Delivery Mins] )
COUNT is for numbers, COUNTA for any non-blank, COUNTROWS for rows.
COUNT संख्यांसाठी, COUNTA कोणत्याही भरलेल्या किंमतीसाठी, COUNTROWS rows साठी. तीन प्रश्न, तीन वेगळी उत्तरे.
COUNT संख्याओं के लिए, COUNTA किसी भी भरी कीमत के लिए, COUNTROWS rows के लिए. तीन सवाल, तीन अलग जवाब.
Read each line:
COUNTROWSdoes not care which columns are blank. It counts rows that survived the filter context.DISTINCTCOUNTcounts each Order ID once. Blank Order ID, if you had one, would count as one extra distinct value.COUNTcounts non-blank numbers. A text column is the wrong argument.COUNTAcounts non-blank values even when the column is text, such as Channel.COUNTBLANKis the question “how many are missing?”, not “how many do we have?”.
COUNT skips blank numbers; COUNTBLANK counts them; DISTINCTCOUNT can treat blank as one value.
COUNT रिकाम्या संख्यांना वगळतो; COUNTBLANK त्यांना मोजतो; DISTINCTCOUNT रिकामा एक किंमत मानू शकतो.
COUNT खाली संख्याओं को छोड़ता है; COUNTBLANK उन्हें गिनता है; DISTINCTCOUNT खाली को एक कीमत मान सकता है.
Where people mix them up
- They drop
Sales[Order ID]into a visual and let Power BI choose an implicit count. Write an explicit measure so the name says Lines or Orders. - They average delivery time with
AVERAGEon the line grain, so a five-line order weighs five times. That is a grain problem, same family as counting. - They use
COUNTROWSof the whole Sales table on a card that sits next to a City slicer and then forget the slicer is on. The measure is filtered. Check the slicer before you call the number wrong. - They
DISTINCTCOUNTa column that is already unique per row, so it matchesCOUNTROWSand they think the functions are identical. Change the column to Order ID and they split.
A small pattern you will reuse
“How many cities sold more than a threshold?” is not DISTINCTCOUNT of City on the fact table alone. You need cities where a measure passes a test. That is COUNTROWS plus FILTER, in the next pattern guides. For this lesson, stay on the column and the row.
Mistakes and calm fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Orders look like line counts | COUNTROWS on Sales |
DISTINCTCOUNT of Order ID |
| Delivery count looks low | Blanks skipped | Compare with COUNTBLANK |
Text column will not COUNT |
COUNT wants numbers |
Use COUNTA |
| Distinct equals rows | Column is unique per row | Count the business key |
Ghabru naka — write the word “lines” or “orders” in the measure name so the card cannot lie politely.
Ravindra Bagale's Tip
Interview line: “COUNT is non-blank numbers, COUNTA is any non-blank, COUNTROWS is rows, DISTINCTCOUNT is unique values and blank can be one of them.” Then give the five-line, two-order example. Got it?
Ravindra Bagale's Tip – मराठी
मुलाखतीचे वाक्य: “COUNT म्हणजे भरलेल्या संख्या, COUNTA म्हणजे कोणतीही भरलेली किंमत, COUNTROWS म्हणजे rows, DISTINCTCOUNT म्हणजे वेगळ्या किंमती आणि रिकामा त्यात एक असू शकतो.” मग पाच lines आणि दोन orders चे उदाहरण द्या. समजलं का?
Ravindra Bagale's Tip – हिंदी
इंटरव्यू की लाइन: “COUNT मतलब भरी संख्याएँ, COUNTA मतलब कोई भी भरी कीमत, COUNTROWS मतलब rows, DISTINCTCOUNT मतलब अलग कीमतें और खाली उनमें एक हो सकता है.” फिर पाँच lines और दो orders का उदाहरण दो. समझ में आया?
Practice task
- Create the five measures above.
- Put them on a table with City.
- Write, for one city, lines versus orders.
- Blank out one delivery minute in a sample file and refresh.
- See which measures moved.
Got it? Say lines, non-blanks, or unique orders before you choose COUNT, COUNTA, COUNTROWS or DISTINCTCOUNT. Next: a trailing 12-month average. Let's continue.
समजलं का? COUNT, COUNTA, COUNTROWS किंवा DISTINCTCOUNT निवडण्याआधी सांगा: lines, भरलेले, की वेगळे orders. पुढे: मागचे बारा महिन्यांचे सरासरी. आता पुढे जाऊया.
समझ में आया? COUNT, COUNTA, COUNTROWS या DISTINCTCOUNT चुनने से पहले बोलो: lines, भरे हुए, या अलग orders. आगे: पिछले बारह महीनों का औसत. आगे बढ़ते हैं.
Frequently asked questions
COUNT vs COUNTROWS?
COUNT counts non-blank numeric values in a column. COUNTROWS counts rows in a table. Prefer COUNTROWS when you only need how many rows.
What does COUNTA count?
Non-blank values of any type in a column — text included.
What does DISTINCTCOUNT include?
Each distinct value once. If blank is present, blank counts as one distinct value.
Why is my order count too high?
You counted lines with COUNTROWS while one order has many lines. Use DISTINCTCOUNT on Order ID.
COUNTBLANK vs COUNT?
COUNTBLANK counts blanks. COUNT ignores them. They answer opposite questions.
Course lesson?
Aggregation functions in the DAX chapter.