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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
adavid999
Helper V
Helper V

Simple Calculate Count

Hi, a simple question hopefully. I have a column with IDs ranging from 1-15. What is the correct DAX if I want to count just those data with ID <=5 and between 8-10?

 

I was trying =CALCULATE(COUNT(Table[ID]),Table[ID] <=5,Table[ID]>=8,Table[ID]<=10) - but I see this isn't correct?!

 

Thanks,


A

 

1 ACCEPTED SOLUTION

Hey. Yes, that will work for your actual condition. First asking it can be <=5 OR >=8 is something that will put the number in one spot and then you add a second mandatory condition that won't break the previous one saying it has to be <=10.

The first post won't work because the conditions in and are not correlative. You can't ask the engine you want a value <5 and >8 at the same time. It's one or the other.

 

Regards,


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

Happy to help!

LaDataWeb Blog

View solution in original post

4 REPLIES 4
ibarrau
Super User
Super User

Hi. I don't think it will work like that. You need to attach those conditions as one. If you just add conditions with "commas" in calculate, those are "AND" one by one. Try this instead:

 

CALCULATE(
    COUNT(Tabla[ID]);
    OR(
        AND(Tabla[ID]>=8 ; Tabla[ID]<=10);
        Tabla[ID] <=5
    )
)

 

Hope this helps,

Regards


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

Happy to help!

LaDataWeb Blog

Thanks @ibarrau that looks like it works. Playing around, I see this also gets same result as your method:

 

=CALCULATE(COUNT(Table[ID]),Table[ID]<=5 || Table[ID]>=8,Table[ID] <=10)

 

May I ask if that also looks OK to you or is it a coincidence that this gets same result?

 

Many thanks,

A

Hey. Yes, that will work for your actual condition. First asking it can be <=5 OR >=8 is something that will put the number in one spot and then you add a second mandatory condition that won't break the previous one saying it has to be <=10.

The first post won't work because the conditions in and are not correlative. You can't ask the engine you want a value <5 and >8 at the same time. It's one or the other.

 

Regards,


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

Happy to help!

LaDataWeb Blog

Thanks @ibarrau for your help. I appreciate it.

Best,

A

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.