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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
rezboot
Frequent Visitor

Distinct count if?

I have data that is similar to the below - 

 

rezboot_1-1723567116369.png

I need create a measure that counts the number of distinct outreaches were made per job filtered by OB Call, OB Call - LVM, and Prescreen.

 

For this example data the returned values should be Job 1 = 3 people, Job 2 = 2 people

 

Can someone please assist on what this would look like?

3 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

dufoq3
Super User
Super User

Hi @rezboot,

 

DAX solution:

 

Output

dufoq3_0-1723706335616.png

 

Candidate DistinctCount = 
VAR _candidates = 
CALCULATE(
    DISTINCTCOUNT(Table1[Candidate]),
    KEEPFILTERS(Table1[Note Action] IN {"OB Call", "OB Call - LVM", "Prescreen"})
)

VAR _blankTotal = 
    IF(ISINSCOPE(Table1[Job #]), _candidates)

RETURN _blankTotal

 

 

Power Query Solution:

 

Output

dufoq3_1-1723706524850.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ndScE7MyVHSUfLKz8gDUoZKsTpwYQVdBZ8wX3TJgKLU4uSi1FSQiFNRZiJ2GefEoqLMVLiUa25iZg6SBiMUUaj5RjjNh8gE+wZjiGG10wjZF2gSsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Note Action" = _t, Candidate = _t, #"Job #" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Job #", Int64.Type}}),
    FilteredRows = Table.SelectRows(ChangedType, each List.Contains({"OB Call", "OB Call - LVM", "Prescreen"}, [Note Action])),
    GroupedRows = Table.Group(FilteredRows, {"Job #"}, {{"All", each List.Count(List.Distinct([Candidate])), Int64.Type}})
in
    GroupedRows

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

Omid_Motamedise
Super User
Super User

Hi,

Use this formula

let
Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
#"Grouped Rows" = Table.Group(Source, {"Job #"}, {{"Number", each _}}),
#"Multiplied Column" = Table.TransformColumns(#"Grouped Rows", {{"Number", each List.Count(List.Distinct(Table.SelectRows(_, (x)=> x[Note Action]="OB Call" or [Note Action]="OB Call - LVM" or x[Note Action]="Prescreen" )[Candiate]))}})
in
#"Multiplied Column"

View solution in original post

5 REPLIES 5
Omid_Motamedise
Super User
Super User

Hi,

Use this formula

let
Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
#"Grouped Rows" = Table.Group(Source, {"Job #"}, {{"Number", each _}}),
#"Multiplied Column" = Table.TransformColumns(#"Grouped Rows", {{"Number", each List.Count(List.Distinct(Table.SelectRows(_, (x)=> x[Note Action]="OB Call" or [Note Action]="OB Call - LVM" or x[Note Action]="Prescreen" )[Candiate]))}})
in
#"Multiplied Column"

rezboot
Frequent Visitor

Thanks! THis was very helpful and worked

You're welcome 😉


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

dufoq3
Super User
Super User

Hi @rezboot,

 

DAX solution:

 

Output

dufoq3_0-1723706335616.png

 

Candidate DistinctCount = 
VAR _candidates = 
CALCULATE(
    DISTINCTCOUNT(Table1[Candidate]),
    KEEPFILTERS(Table1[Note Action] IN {"OB Call", "OB Call - LVM", "Prescreen"})
)

VAR _blankTotal = 
    IF(ISINSCOPE(Table1[Job #]), _candidates)

RETURN _blankTotal

 

 

Power Query Solution:

 

Output

dufoq3_1-1723706524850.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ndScE7MyVHSUfLKz8gDUoZKsTpwYQVdBZ8wX3TJgKLU4uSi1FSQiFNRZiJ2GefEoqLMVLiUa25iZg6SBiMUUaj5RjjNh8gE+wZjiGG10wjZF2gSsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Note Action" = _t, Candidate = _t, #"Job #" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Job #", Int64.Type}}),
    FilteredRows = Table.SelectRows(ChangedType, each List.Contains({"OB Call", "OB Call - LVM", "Prescreen"}, [Note Action])),
    GroupedRows = Table.Group(FilteredRows, {"Job #"}, {{"All", each List.Count(List.Distinct([Candidate])), Int64.Type}})
in
    GroupedRows

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

lbendlin
Super User
Super User

lbendlin_0-1723596518945.png

 

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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