Forum Discussion
Adding conditional unique index column based on several criterias
- 9 years agoThank you so much, looks very useful. I will try to implement this and get back with feedback as soon as possible. Thanks again!
Hi Marianne,
if my understanding of your request is correct, then PowerBI isn't the right tool for it:
You're importing data in Power BI and want to create a value that sticks to the imported data, also when the next refresh is done?
Problem is, that there is currently no concept for storing such data in PBI. So you would need to export your new table with the newly generated ID's in order for them to be kept ... & reimported & merged with the new data (2nd run), where again new rows with empty ID's will come in.
- MarianneElver9 years agoHelper IIIHi Imke, Thanks for your reply. I see, would data also not be stored if the generated IDs were fed/added into another table? I no, then is there any other method withing PBI for calculating the unique numbers of customers (and use this number in various other calculations) if the criteria for not counting the same customer twice are met? Thanks in advance, Marianne
- ImkeF9 years agoCommunity Champion
Yes, you can create an Index-column like this, that will be recreated completely everytime you refresh your query like this:
let Source = Tabelle2, #"Grouped Rows" = Table.Group(Source, {"Phone"}, {{"All", each Table.AddIndexColumn(_, "NestedIndex",1,1), type table}}), TelIndex = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1), HasMatches = Table.AddColumn(TelIndex, "Custom", each List.Count(List.Union({[All][email], [All][Customer Number], [All][Customer name]})) <> List.Count(List.Distinct(List.Union({[All][email], [All][Customer Number], [All][Customer name]})))), #"Expanded All" = Table.ExpandTableColumn(HasMatches, "All", {"Customer name", "Customer Number", "email", "NestedIndex"}, {"Customer name", "Customer Number", "email", "NestedIndex"}), #"Added Custom" = Table.AddColumn(#"Expanded All", "NewIndex", each if [Custom] = false then Text.From([Index])&"-"& Text.From([NestedIndex]) else [Index]), #"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"NestedIndex", "Index", "Custom"}) in #"Removed Columns1"Just replace "Tabelle2" in the Source-step by the name of your query/table.
Question is what shall be returned, if there are more than 2 rows per telephone-number, and only 2 are matching an one is distinct. Using this, code, the non-matching row would also get the same ID. Not sure if this is what you want.
- MarianneElver9 years agoHelper IIIThank you so much, looks very useful. I will try to implement this and get back with feedback as soon as possible. Thanks again!