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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
User1999
Regular Visitor

How to show yes or no for a category column

d8ac3c94-d83f-4d45-ae81-5b8c32f8b59f.jpeg

 Here is the similar kind of table I would be using it in the powerbi. I wanted to show a table visual that show the ID and for that particular ID if the category is present we need to show Y ( yes ) if not then N (No). 

I wanted show it in this way in powerbi table visual 

 

5fee99d8-8e97-4ce5-b0b6-b833dfceb795.jpeg

 

2 ACCEPTED SOLUTIONS
Chakravarthy
Resolver II
Resolver II

Hi @User1999 

I have loaded the table

Chakravarthy_2-1711988210863.png

Please Copy this code in Advance Editor

#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID"}, "Attribute", "Value"),
#"Pivoted Column" = Table.Pivot(#"Unpivoted Columns", List.Distinct(#"Unpivoted Columns"[Value]), "Value", "Attribute", List.Count),
Custom1 = Table.TransformColumns(#"Pivoted Column",
{
{
"snacks",each
if _ = 1 then "Y"
else "N"
},
{
"biscuits",each
if _ = 1 then "Y"
else "N"
},
{
"beverages",each
if _ = 1 then "Y"
else "N"
},
{
"chocolates",each
if _ = 1 then "Y"
else "N"
}
}
)
in
Custom1

 

FULL CODE:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyMlTSUSrOS0zOLlaK1YGLJGUWJ5dmlqCKpZalFiWmp6IIJmfkJ+fnJJbARI2NDXCKohoKFUM11MTEBMk9sQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Category = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"ID", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID"}, "Attribute", "Value"),
#"Pivoted Column" = Table.Pivot(#"Unpivoted Columns", List.Distinct(#"Unpivoted Columns"[Value]), "Value", "Attribute", List.Count),
Custom1 = Table.TransformColumns(#"Pivoted Column",
{
{
"snacks",each
if _ = 1 then "Y"
else "N"
},
{
"biscuits",each
if _ = 1 then "Y"
else "N"
},
{
"beverages",each
if _ = 1 then "Y"
else "N"
},
{
"chocolates",each
if _ = 1 then "Y"
else "N"
}
}
)
in
Custom1

Finally The Power Query gets transformed as below:

Chakravarthy_3-1711988360460.png

 

Pull the required in Table Visual as below:

Chakravarthy_4-1711988468535.png

 

View solution in original post

Ahmedx
Super User
Super User

4 REPLIES 4
Ahmedx
Super User
Super User

pls try this

Screenshot_2.png

d_rohlfs
Helper I
Helper I

If you don't want to get into trnasposing and pivoting the table in Power Query, I would just create a few measures. There will need to be one measure for each category, but they are all very simple to setup. 
Each measure will follow this format:
            Snacks = IF( 'Table1'[Category] = "Snacks", TRUE(), FALSE())
Repeat this for all categories. Then you can put the 'Table1'[ID] column into a table or matrix and place your meaures along with it.

Chakravarthy
Resolver II
Resolver II

Hi @User1999 

I have loaded the table

Chakravarthy_2-1711988210863.png

Please Copy this code in Advance Editor

#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID"}, "Attribute", "Value"),
#"Pivoted Column" = Table.Pivot(#"Unpivoted Columns", List.Distinct(#"Unpivoted Columns"[Value]), "Value", "Attribute", List.Count),
Custom1 = Table.TransformColumns(#"Pivoted Column",
{
{
"snacks",each
if _ = 1 then "Y"
else "N"
},
{
"biscuits",each
if _ = 1 then "Y"
else "N"
},
{
"beverages",each
if _ = 1 then "Y"
else "N"
},
{
"chocolates",each
if _ = 1 then "Y"
else "N"
}
}
)
in
Custom1

 

FULL CODE:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyMlTSUSrOS0zOLlaK1YGLJGUWJ5dmlqCKpZalFiWmp6IIJmfkJ+fnJJbARI2NDXCKohoKFUM11MTEBMk9sQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Category = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"ID", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID"}, "Attribute", "Value"),
#"Pivoted Column" = Table.Pivot(#"Unpivoted Columns", List.Distinct(#"Unpivoted Columns"[Value]), "Value", "Attribute", List.Count),
Custom1 = Table.TransformColumns(#"Pivoted Column",
{
{
"snacks",each
if _ = 1 then "Y"
else "N"
},
{
"biscuits",each
if _ = 1 then "Y"
else "N"
},
{
"beverages",each
if _ = 1 then "Y"
else "N"
},
{
"chocolates",each
if _ = 1 then "Y"
else "N"
}
}
)
in
Custom1

Finally The Power Query gets transformed as below:

Chakravarthy_3-1711988360460.png

 

Pull the required in Table Visual as below:

Chakravarthy_4-1711988468535.png

 

jmarciogsousa
Frequent Visitor

You can try to use the matrix with this measure:

jmarciogsousa_0-1711987691090.png

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.