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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
marcss
New Member

ID Count with filter

I've got the date as shown below:

 

TableID
1564080
1648747
1701842
1701858
1701859
1701860
2760287
2760304
2760371
2760394
2760397
2760400
2760514

 

I nees to get tow measures:

  1-The Distinct count of IDs where table field equals 1

  2-The Distinct count of IDs where table field equals 2

 

I've tryed:

Measure = CALCULATE(
DISTINCTCOUNT(data[ID]),FILTER(data,data[ID]="2"))

 

And the count is not correct

1 ACCEPTED SOLUTION

Try then:

Measure 1 = 
CALCULATE(
    DISTINCTCOUNT( Data[ID] ),
    REMOVEFILTERS( Data ),
    Data[Type] = 1
)

View solution in original post

4 REPLIES 4
FreemanZ
Super User
Super User

hi @marcss 

try like:

count1 =
COUTROWS(
    CALCULATETABLE(
        VALUES(data[ID]),
        data[Table]=1
    )
)
intruder
Frequent Visitor

Hi,

 

sounds simple.

 

If you want to visualize this in any of the P BI visual, simply DISTINCTCOUNT of IDs should work. You just need to put the column that you want to split the results by onto the visualization. The filter context will do the rest.

 

If you want to create separate visuals, each for each type, you can either use filters on the filter pane or add a filter argument to the `CALCULATE` function. In the first case, DISTINCTCOUNT measure would work. 

 

For the measure that use the expression for filtering, go for this:

 

Measreu 1 = 
CALCULATE(
    DISTINCTCOUNT( Data[ID] ),
    Data[Type] = 1
)

Measreu 2 = 
CALCULATE(
    DISTINCTCOUNT( Data[ID] ),
    Data[Type] = 2
)

 

However, I assume there is no need to create a separate measures for your case. Create a DISTINCTCOUNT measure and put it on the visualization along with the [Type] column (or any other column that you want to display with the measure).

It doesn't work, both measures show the same value:

marcss_0-1677050700420.png

 

Try then:

Measure 1 = 
CALCULATE(
    DISTINCTCOUNT( Data[ID] ),
    REMOVEFILTERS( Data ),
    Data[Type] = 1
)

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

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