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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Anonymous
Not applicable

Distinct count of column value from a table based on measure in a another table

 

This is a followup to previous post:  Solved: Re: Help with grouped sum - Microsoft Power BI Community

 

I have these two tables A and B.   

All ConsumerIdtaskcodes in Table A are also in Table B.

 

Links to CSV A and B:

https://drive.google.com/file/d/1-PquFaIlYsS_qeY-D1D1uiwXl2NZSUH8/view?usp=sharing

https://drive.google.com/file/d/1_pOz3eAUAxr5-tAdXAeZxrXwPbRLVQOE/view?usp=sharing

 

There are some consumerIdtaskcode in B but not in A.

 

Table B has confidencescores column but table A does not.

 

Olajumi_0-1629656255073.png

 

The fisrt task is to create a measure to count the ConsumerIdTaskcode in table B with confidence score (aggregated per ConsumeridTaskcode) above a threshhold (say 71).  The following measure works for that:   

 

Count Over 71 =
COUNTROWS (
    FILTER (
        VALUES ( 'report ConsumerTaskCodes'[ConsumerIdTaskcode] ),
        CALCULATE ( SUM ( 'report ConsumerTaskCodes'[confidenceScore] ) ) > 71
    )
)

Table B result

Olajumi_1-1629656788929.png

 

Question 1:

Here is my next task:

Identify and create a measure to determine ONLY distinct count of ConsumerIdtaskcodes in Table A that are also in B with confidencescore  (in B) above 71.

 

Answer should be 2:  From Table A

   

Table A result

Olajumi_2-1629657015653.png

 

Question 2.  By extension, create a dax calculation to  

List the codes that are in Table B but not in A (still with Confidencescore > 71.

 

Links to CSV A and B:

 

https://drive.google.com/file/d/1-PquFaIlYsS_qeY-D1D1uiwXl2NZSUH8/view?usp=sharing

https://drive.google.com/file/d/1_pOz3eAUAxr5-tAdXAeZxrXwPbRLVQOE/view?usp=sharing

 

@mahoneypat 

2 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

@Anonymous Question 1:

Count Over 71 Distinct = 
VAR __TableA = DISTINCT('dataTableA'[ConsumerIdTaskcode])
VAR __TableB =
    SELECTCOLUMNS(
        FILTER(
            SUMMARIZE(
                'report ConsumerTaskCodes',
                [ConsumerIdTaskcode],
                "__Confidence",SUM('report ConsumerTaskCodes'[confidenceScore])
            ),
            [__Confidence] > 71
        ),
        "ConsumerIdTaskcode",[ConsumerIdTaskcode]
    )
RETURN
    COUNTROWS(INTERSECT(__TableA,__TableB))

 

Question 2:

Count Over 71 Distinct Reverse = 
VAR __TableA = DISTINCT('dataTableA'[ConsumerIdTaskcode])
VAR __TableB =
    SELECTCOLUMNS(
        FILTER(
            SUMMARIZE(
                'report ConsumerTaskCodes',
                [ConsumerIdTaskcode],
                "__Confidence",SUM('report ConsumerTaskCodes'[confidenceScore])
            ),
            [__Confidence] > 71
        ),
        "ConsumerIdTaskcode",[ConsumerIdTaskcode]
    )
RETURN
    COUNTROWS(EXCEPT(__TableB,__TableA))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

@Anonymous Try:

Count Over 71 Distinct Reverse = 
VAR __TableA = DISTINCT('dataTableA'[ConsumerIdTaskcode])
VAR __TableB =
    SELECTCOLUMNS(
        FILTER(
            SUMMARIZE(
                'report ConsumerTaskCodes',
                [ConsumerIdTaskcode],
                "__Confidence",SUM('report ConsumerTaskCodes'[confidenceScore])
            ),
            [__Confidence] > 71
        ),
        "ConsumerIdTaskcode",[ConsumerIdTaskcode]
    )
  VAR __Ids = EXCEPT(__TableB,__TableA)
  VAR __Table = FILTER('report ConsumerTaskCodes',[ConsumerIdTaskcode] IN __Ids)
RETURN
  CONCATENATEX(__Table,[taskCode],",")


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

10 REPLIES 10
ryan_mayu
Super User
Super User

@Anonymous 

you can try this

Measure = 
VAR tbl=SUMMARIZE('dataTableB',dataTableB[ConsumerIdTaskcode],"sum",sum(dataTableB[confidenceScore]))
return COUNTROWS(FILTER(tbl,[sum]>71))

Measure 2 = 
VAR tbl=ADDCOLUMNS(SUMMARIZE('dataTableB',dataTableB[ConsumerIdTaskcode],"sum",sum(dataTableB[confidenceScore])),"check",if(maxx(FILTER(dataTableA,dataTableA[ConsumerIdTaskcode]=dataTableB[ConsumerIdTaskcode]),dataTableA[ConsumerIdTaskcode])<>"","Yes"))
return COUNTROWS(FILTER(tbl,[sum]>71&&[check]="Yes"))

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Greg_Deckler
Community Champion
Community Champion

@Anonymous Question 1:

Count Over 71 Distinct = 
VAR __TableA = DISTINCT('dataTableA'[ConsumerIdTaskcode])
VAR __TableB =
    SELECTCOLUMNS(
        FILTER(
            SUMMARIZE(
                'report ConsumerTaskCodes',
                [ConsumerIdTaskcode],
                "__Confidence",SUM('report ConsumerTaskCodes'[confidenceScore])
            ),
            [__Confidence] > 71
        ),
        "ConsumerIdTaskcode",[ConsumerIdTaskcode]
    )
RETURN
    COUNTROWS(INTERSECT(__TableA,__TableB))

 

Question 2:

Count Over 71 Distinct Reverse = 
VAR __TableA = DISTINCT('dataTableA'[ConsumerIdTaskcode])
VAR __TableB =
    SELECTCOLUMNS(
        FILTER(
            SUMMARIZE(
                'report ConsumerTaskCodes',
                [ConsumerIdTaskcode],
                "__Confidence",SUM('report ConsumerTaskCodes'[confidenceScore])
            ),
            [__Confidence] > 71
        ),
        "ConsumerIdTaskcode",[ConsumerIdTaskcode]
    )
RETURN
    COUNTROWS(EXCEPT(__TableB,__TableA))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler 

In Question 2,  how do I determine the actual Taskcodes (not ConsumerIdTaskcode ) that are in Table B but not in A (still with Confidencescore > 71?   This is where I was heading and thougt I could figure it out, but proving difficult.   Thanks.  I think first dax is fine. 

@Anonymous Just use CONCATENATEX instead of COUNTROWS.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

 

@Greg_Deckler 

The first part of ConsumerIdTaskcode is a whole number (variable lenght) while the other part is a text.  E.g. for ConsumerIdTaskcode 1961L160,  the Taskcode is  L160.    So I need to pick the text out of ConsumerIdTaskcode to represent the Taskcode.    

 

@Anonymous Use CONCATENATEX(EXCEPT(__TableB,__TableA), RIGHT([ConsumerIdTaskcode,4),", ") ?

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thank you again, @Greg_Deckler , can we report this based on the column Taskcode instead ?   In real life data,  the Taskcode part of ConsumerIdTaskcode is not always 4 characters - very much varies.  So also does the ConsumerId.   So it is safer to report the column Taskcode standalone. 

@Anonymous Try:

Count Over 71 Distinct Reverse = 
VAR __TableA = DISTINCT('dataTableA'[ConsumerIdTaskcode])
VAR __TableB =
    SELECTCOLUMNS(
        FILTER(
            SUMMARIZE(
                'report ConsumerTaskCodes',
                [ConsumerIdTaskcode],
                "__Confidence",SUM('report ConsumerTaskCodes'[confidenceScore])
            ),
            [__Confidence] > 71
        ),
        "ConsumerIdTaskcode",[ConsumerIdTaskcode]
    )
  VAR __Ids = EXCEPT(__TableB,__TableA)
  VAR __Table = FILTER('report ConsumerTaskCodes',[ConsumerIdTaskcode] IN __Ids)
RETURN
  CONCATENATEX(__Table,[taskCode],",")


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

You are awesome!

I did some spot checks and it is looking good so far.

 

Olajumi_0-1629725765502.png

 

Can it be made a distinct list and ordered in a column?

@Greg_Deckler 

@Anonymous Well, you can't return a table in a measure. It would have to be a calculated table. I feel like I am working with like half of the information about what you are trying to accomplish.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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 Solution Authors
Top Kudoed Authors