Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi All
I have tried to solve this problem for a while now but got stuck, and coulnd't find a previous post about it.
I have two tables. Table1 has list of customer ids and product ids, one customer id can occur multiple times with different or same product id. Table2 has a column with the unique customer ids.
I would like to create new columns for each product id in Table 2 that returns 1 if the pair of customer id and product id is present in table1.
Example:
Order Number | Product Code |
1 | a |
1 | b |
1 | c |
1 | d |
2 | c |
2 | d |
2 | a |
2 | a |
2 | a |
3 | c |
4 | d |
4 | d |
Table 2:
Order Number | a | b | c | d |
1 | 1 | 1 | 1 | 1 |
2 | 1 | 0 | 1 | 1 |
3 | 0 | 0 | 1 | 0 |
4 | 0 | 0 | 0 | 1 |
I am using the below expression to create the new columns:
Solved! Go to Solution.
Hi,
This M code works
let
Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Order Number", Int64.Type}, {"Product Code", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each 1),
#"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[#"Product Code"]), "Product Code", "Custom", List.Min)
in
#"Pivoted Column"
Hope this helps.
Hi,
This M code works
let
Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Order Number", Int64.Type}, {"Product Code", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each 1),
#"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[#"Product Code"]), "Product Code", "Custom", List.Min)
in
#"Pivoted Column"
Hope this helps.
Thank you for your reply. This is exactly what i was looking for. Thank you very much.
You are welcome.
Hi @egabor88,
One of the solutions:
1) You create two tables with unique products and orders.
For example, like this:
Orders = DISTINCT ( 'Table'[Order Number] )
Products = DISTINCT ( 'Table'[Product Code] )
2) You create one-to-many connections between the newly created tables and your fact table.
3) Once done, you add a matrix visual and compose a simple measure like this one:
Measure =
VAR counter = COUNTROWS ( 'Table' ) + 0
RETURN IF ( counter > 0, 1, 0 )
And it works (see the attached PBIX file if needed):
Best Regards,
Alexander
Hi @barritown
Thank you for your reply. Unfortuantely i need a table not just a visual. I would like to make further calculations with these new columns.
User | Count |
---|---|
98 | |
90 | |
82 | |
73 | |
67 |
User | Count |
---|---|
115 | |
102 | |
98 | |
71 | |
67 |