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

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

Reply
Anonymous
Not applicable

How to count values of one column by another column

Hello,

 

So if I have a table like this that has a list of ZIPs delivered to and the week they're delivered, except for the bold column. That's the column I need to build.

 

tRaw

ZIP Week Weekly Total
12345 1 3
12345 1 3
12345 1 3
67890 1 2
67890 1 2
12345 2 2
12345 2 2
67890 2 1

 

 

I've tried 

Weekly Total= 
CALCULATE(
   DISTINCTCOUNT(tRaw[ZIP]),
   ALLEXCEPT(tRaw,tRaw[Week])
   )

but what ends up coming out is

 

ZIP Week Weekly Total
12345 1 5
12345 1 5
12345 1 5
67890 1 5
67890 1 5
12345 2 3
12345 2 3
67890 2 3

 

Any help would be appreciated!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Figured it out

 

Don't need DISTINCTCOUNT, COUNT worked perfectly

 

Column 2 = calculate(
count(tRaw[ZipCode]),
ALLEXCEPT(tRaw, traw[week], tRaw[ZipCode])
)

View solution in original post

5 REPLIES 5
AilleryO
Memorable Member
Memorable Member

Hi,

 

You should do a COUNT not a DISTINCTCOUNT, which prevents you from havnig the expected result.

Both solutions hereunder, would do the trick :

As @parry2k proposed :

Weekly Total v2 = 
CALCULATE(
   COUNT(tRaw[ZIP]),
   ALLEXCEPT(tRaw,tRaw[Week],tRaw[ZIP])
   )

Or if you like to have another version of the solution, you could do :

Weekly Total v1 = 
CALCULATE(
   COUNT(tRaw[ZIP]),
   KEEPFILTERS(tRaw[Week]), KEEPFILTERS(tRaw[ZIP])
   )

Both soltions provides expected results. Let us know...

Anonymous
Not applicable

Hi @Anonymous 

I am so glad that you have solved your problem , please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regard

Community Support Team _ Ailsa Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

parry2k
Super User
Super User

@Anonymous you should add Zip column in ALLEXCEPT too:

 

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Check my latest video on Filters and Sparklines https://youtu.be/wmwcX8HvNxc

 

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.

Anonymous
Not applicable

Figured it out

 

Don't need DISTINCTCOUNT, COUNT worked perfectly

 

Column 2 = calculate(
count(tRaw[ZipCode]),
ALLEXCEPT(tRaw, traw[week], tRaw[ZipCode])
)
Anonymous
Not applicable

Like so?

 
Column =
CALCULATE(
DISTINCTCOUNT(tRaw[ZipCode]),
ALLEXCEPT(tRaw ,tRaw[Week], tRaw[ZipCode])
)
 
I tried that and it just returns 1 as every value

Helpful resources

Announcements
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 Kudoed Authors