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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
elinevans
Helper I
Helper I

Count if relating to a specific service

Hello, 

 

I am building a report to see how many client were contacted wihtin 48 hours of referral when referred into service A, however if they were contacted through any other service in the 48hrs period then that would count as the client being contacted on behalf of service A. 

I have 2 tables like the following

Client IDService
1234

A

3214A
3214B
2341C
2145B
Client IDServiceContact DateContacted in 48
1234A12/12/2020True
3214A01/12/2020False
3214B30/11/2021True
2145B01/12/2020True

 

I want to have a distinct count of clients that have been contacted in 48hrs, but they have to be associated with Service A. For example, Client 3214 was not contacted within 48hrs within service A but they were contacted through service B, and because they are also in service A this would be counted. However, 2145 would not be counted as they are not in service A. 1234 would be counted becuase they have been contacted in 48hrs and are in service A.

 

Something along the lines of a distinct count of clients in any service who have been contacted in 48hrs only if they are also a part of service A. 

 

Hope this makes sense

 

Thanks

Elin

2 ACCEPTED SOLUTIONS
smpa01
Super User
Super User

@elinevans  you can use a measure like this

 

Measure = 
VAR _left =
    SUMMARIZE (
        CALCULATETABLE (
            'Table 1',
            'Table 1'[Service] IN { "A" },
            ALLEXCEPT ( 'Table 1', 'Table 1'[Client ID] )
        ),
        'Table 1'[Client ID]
    )
VAR _right =
    SUMMARIZE (
        FILTER ( 'Table 2', 'Table 2'[Contacted in 48] = TRUE () ),
        'Table 2'[Client ID]
    )
RETURN
    COUNTX ( INTERSECT ( _left, _right ), 'Table 1'[Client ID] )

 

 

smpa01_1-1639676945521.png

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

Anonymous
Not applicable

Hi @elinevans ,

 

This is a measure to count the clients for specific service.

Measure = CALCULATE(DISTINCTCOUNT(TableB[Client ID]),
            FILTER(ALL(TableB),
                (TableB[Service]="A"&&TableB[Contacted in 48]="True")||
                (CALCULATE(MAX(TableB[Contacted in 48]),ALLEXCEPT(TableB,TableB[Client ID]))="True"&&"A" in CALCULATETABLE(VALUES(TableB[Service]),ALLEXCEPT(TableB,TableB[Client ID])))
                    ))

 Capture.PNG

You could create a slicer and replace the "A" to SELECTEDVALUE('slicer'[service]), then you can calculate for the specified service.

 

Best Regards,

Jay

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @elinevans ,

 

This is a measure to count the clients for specific service.

Measure = CALCULATE(DISTINCTCOUNT(TableB[Client ID]),
            FILTER(ALL(TableB),
                (TableB[Service]="A"&&TableB[Contacted in 48]="True")||
                (CALCULATE(MAX(TableB[Contacted in 48]),ALLEXCEPT(TableB,TableB[Client ID]))="True"&&"A" in CALCULATETABLE(VALUES(TableB[Service]),ALLEXCEPT(TableB,TableB[Client ID])))
                    ))

 Capture.PNG

You could create a slicer and replace the "A" to SELECTEDVALUE('slicer'[service]), then you can calculate for the specified service.

 

Best Regards,

Jay

VahidDM
Super User
Super User

Hi @elinevans 

 

This is my suggestion:

Measure 2 = 
Var _A = 
filter(ADDCOLUMNS(SUMMARIZE('Table (2)','Table (2)'[Client ID],"Service",MIN('Table (2)'[Service])),"T/F",CALCULATE(COUNTROWS('Table (2)'),'Table (2)'[Contacted in 48]=true())),[Service]="A")
return
COUNTROWS(_A)

 

Output:

VahidDM_0-1639693890255.png

 

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

smpa01
Super User
Super User

@elinevans  you can use a measure like this

 

Measure = 
VAR _left =
    SUMMARIZE (
        CALCULATETABLE (
            'Table 1',
            'Table 1'[Service] IN { "A" },
            ALLEXCEPT ( 'Table 1', 'Table 1'[Client ID] )
        ),
        'Table 1'[Client ID]
    )
VAR _right =
    SUMMARIZE (
        FILTER ( 'Table 2', 'Table 2'[Contacted in 48] = TRUE () ),
        'Table 2'[Client ID]
    )
RETURN
    COUNTX ( INTERSECT ( _left, _right ), 'Table 1'[Client ID] )

 

 

smpa01_1-1639676945521.png

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.