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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
RS1
New Member

Group by one column and only select rows where values in another column occur in both lists

I'm looking to find a distinct count of Column 1 where, when grouping by Column 1, values in Column 2 may be found in two lists. 

 

List 1 = {1, 2}

List 2 = {X, Y}

 

A4
A2
AX
B3
BZ
C1
CY
CQ
D2
D

X

 

Here the expected count would be 3, because:

Where Column 1 = A, Column 2 contains values {4, 2, X}. Since 2 is in {1, 2} and X is in {X, Y}, the criteria is met

Where Column 1 = C, Column 2 contains values {1, Y, Q}. Since 1 is in {1, 2} and Y is in {X, Y}, the criteria is met

Where Column 1 = D, Column 2 contains values {2, X}. Since 2 is in {1, 2} and X is in {X, Y}, the criteria is met

 

I'm not sure how to create a measure in Power BI that accomplishes this. Any help would be greatly appreciated!

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Why would that need to be a measure?

Here's a Power Query version

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJRitWBsIzgrAgwywnIMoazosAsZyDLEM6KhLMCwSwXuCkuEFNiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Test", each List.Contains({"1","2"},[Column2]) or List.Contains({"X","Y"},[Column2])),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Test] = true)),
    #"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Column1"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Other Columns")
in
    #"Removed Duplicates"

View solution in original post

2 REPLIES 2
v-xinruzhu-msft
Community Support
Community Support

Hi @RS1 

You can refer to the following measure

Sample data 

vxinruzhumsft_1-1690166779841.png

Measure = var _list1= {1, 2}
var _list2={"X","Y"}
var _conv=CONCATENATEX(FILTER(ALLSELECTED('Table'),[Type1] in VALUES('Table'[Type1])),[Type2],",")
return IF(COUNTROWS(FILTER(_list1,CONTAINSSTRING(_conv,[Value])))>0&&COUNTROWS(FILTER(_list2,CONTAINSSTRING(_conv,[Value])))>0,"meet","false")

Output

vxinruzhumsft_0-1690166763669.png

Best Regards!

Yolo Zhu

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

 

lbendlin
Super User
Super User

Why would that need to be a measure?

Here's a Power Query version

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJRitWBsIzgrAgwywnIMoazosAsZyDLEM6KhLMCwSwXuCkuEFNiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Test", each List.Contains({"1","2"},[Column2]) or List.Contains({"X","Y"},[Column2])),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Test] = true)),
    #"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Column1"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Other Columns")
in
    #"Removed Duplicates"

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors