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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
Anonymous
Not applicable

Flag based on all data in the table

Hello

 

I have the following dataset 

 

CustomerIDProductID
000AA1
000CC3
000CC1
000FF3
000BB1
000DD1
000FF2

 

What I'm trying to do is to add a column that will flag for the customer whether they have other purchases in the table, so I want my final dataset to look like this

 

CustomerIDProductIDProduct1FlagProduct2FlagProduct3Flag
000AA1YNN
000CC3YNY
000CC1YNY
000FF3NYY
000BB1YNN
000DD1YNN
000FF2NYY

 

Notice that CustomerID 000CC has a flag in column Product1Flag and Product3Flag even when that record appears before their purchase of Product 1.

 

In the end that table should give me all the products purchased by that customer in a single row.

 

Im very very new to PowerBI and DAX functions - i recognize this is probably very easy so thank you for your patience here

2 REPLIES 2
Anonymous
Not applicable

Hello @amitchandak 

The issue is me here.  Very new to this.  Where exactly do I include this large code set and which fields do i modify to adjust to my actual query?

amitchandak
Super User
Super User

@Anonymous , Please try this power query code

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAwcHRU0lEyVIrVAfOcnYE8YxQeXM7NDVnOyQlZzsUFQ6WRUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CustomerID = _t, ProductID = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"CustomerID", type text}, {"ProductID", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Cnt", each 1),
#"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Added Custom", {{"ProductID", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Added Custom", {{"ProductID", type text}}, "en-US")[ProductID]), "ProductID", "Cnt", List.Max),
#"Changed Type1" = Table.TransformColumnTypes(#"Pivoted Column",{{"1", type text}, {"3", type text}, {"2", type text}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type1","1","Y",Replacer.ReplaceText,{"1", "3", "2"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",null,"N",Replacer.ReplaceValue,{"1", "3", "2"})
in
#"Replaced Value1"

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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