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
tchchan3
New Member

Need Help - Filtering Distinctcount and Counting DistinctCount Count

Hello all,

 

Fairly new to PowerBi and Query,


Looking for some guidance on how to go about this....

 

This is my pivot table result within my data model 

Example:

 

 DistinctCount of Words
12341
45662
75981
12341
12343

 

Im looking for a way to display my distintcount results 

Results of Distinct CountCount
13
22
>=22
1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @tchchan3 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

c1.png

 

Test:

c2.png

 

You may create measures as below.

DistinctCount of Words = SUM('Table'[Value])
Result Measure = 
var t = 
ADDCOLUMNS(
    'Table',
    "Re",
    [DistinctCount of Words]
)
var tab = 
ADDCOLUMNS(
    Test,
    "Result",
    SWITCH(
        [Results of Distinct Count],
        "1",
        COUNTROWS(
            FILTER(
                t,
                [Re]=1
            )
        ),
        "2",
        COUNTROWS(
            FILTER(
                t,
                [Re]=2
            )
        ),
        ">=2",
        COUNTROWS(
            FILTER(
                t,
                [Re]>=2
            )
        )
    )
)
return
SUMX(
    tab,
    [Result]
)

 

Result:

c3.png

 

Best Regards

Allan

 

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

View solution in original post

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @tchchan3 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

c1.png

 

Test:

c2.png

 

You may create measures as below.

DistinctCount of Words = SUM('Table'[Value])
Result Measure = 
var t = 
ADDCOLUMNS(
    'Table',
    "Re",
    [DistinctCount of Words]
)
var tab = 
ADDCOLUMNS(
    Test,
    "Result",
    SWITCH(
        [Results of Distinct Count],
        "1",
        COUNTROWS(
            FILTER(
                t,
                [Re]=1
            )
        ),
        "2",
        COUNTROWS(
            FILTER(
                t,
                [Re]=2
            )
        ),
        ">=2",
        COUNTROWS(
            FILTER(
                t,
                [Re]>=2
            )
        )
    )
)
return
SUMX(
    tab,
    [Result]
)

 

Result:

c3.png

 

Best Regards

Allan

 

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

Jimmy801
Community Champion
Community Champion

Hello @tchchan3 

 

you can solve this in DAX by creating a new table using the SUMMARIZE function where you make the distinct count and depending on the output of this, writing in a new column 1, 2 or >=2. Then using this created table in your pivot-table. Here a possible code

CountDistinctCount = SUMMARIZE(YOURTABLE  
      , YOURTABLE[COLUMNTODISTINCTCOUNT], "CountOfDistinctCount", if (COUNT(YOURTABLE[COLUMNTODISTINCTCOUNT])=1, "1", if (COUNT(YOURTABLE[COLUMNTODISTINCTCOUNT])=2, "2", ">=2")))

Jimmy801_0-1607498356688.png


If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

mussaenda
Super User
Super User

Hi @tchchan3 ,

 

I did not get the desired result.

you have 2 and >=2 ?

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.