I’m trying to create a custom [Key] which is used to group items. It’s a combination of:
[Project]
conditional total where if previous row [Concat] is not same as current row [Concat] add +1
PS: simple grouping of [Project] does not work, because you need to take into account Field 1 & Field 2, if it’s filled, the next item should be +1. => see Project B for precise behavior.
Hi @Wilknsn, I noticed you didn’t provide a PBIX file. Providing one will help users and experts find a solution to your inquiry faster and better.
A perfect initial question includes all of the following:
A clear explanation of the problem you are experiencing
A mockup of the results you want to achieve
Your current work-in-progress PBIX file
Your underlying data file (to allow us to go into Power Query if necessary to transform your data and/or data model – often DAX questions really end up being data modeling solutions)
Yes, M code looks sequential but that’s not required, the engine will always follow the dependency chain. I usually place my variables on top so interaction with the UI doesn’t affect them.
Thanks again, just FYI, I added an additional line in the function to cover the case where you would have just one unique line after the other (in the sample, there would always be at least 2 per project).
=> 3rd if statement
each
if List.IsEmpty( List.RemoveNulls( { BufferedField1{[row]-1} } )) and BufferedProject{[row]} <> BufferedProject{[row]-1}
then [Counter=1, row=[row]+1, Value= BufferedProject{[row]}] else
if List.IsEmpty( List.RemoveNulls( { BufferedField1{[row]-1} } )) and BufferedProject{[row]} = BufferedProject{[row]-1}
then [Counter=[Counter], row=[row]+1, Value= BufferedProject{[row]}] else
if not List.IsEmpty( List.RemoveNulls( { BufferedField1{[row]-1} } )) and BufferedProject{[row]} <> BufferedProject{[row]-1}
then [Counter=1, row=[row]+1, Value= BufferedProject{[row]}] else
if not List.IsEmpty( List.RemoveNulls( { BufferedField1{[row]-1} } )) and BufferedProject{[row]} = BufferedProject{[row]-1}
then [Counter=[Counter]+1, row=[row]+1, Value= BufferedProject{[row]}]
else [Counter=1, row=[row]+1, Value= BufferedProject{[row]+1}]
){[Index]-1} // Get record for current row
),