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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX to return 1 if values in two columns are consecutive and the same

Hi Experts

 

i am trying to work out where the TASK ID Project ID are consective for two or more rows then return a value of one in a new column other wise 0. See below. not sure on how to do the DAX

 

Task IDProject IDExpected Result
123949810221
123949810221
123949818090
1239498105660
123944612651
123944612651
1239446194650
1 ACCEPTED SOLUTION
Kishore_KVN
Super User
Super User

Hello @Anonymous , I am not sure if you are looking for this. I have created three columns so that you can understand clearly. 

Output looks like this:

Kishore_KVN_0-1685538075540.png

 

Three columns DAX will be like this:

Key Column = 'Table'[Task ID]&'Table'[Project ID]
Counting = CALCULATE(COUNT('Table'[Key Column]),ALLEXCEPT('Table','Table'[Key Column]))
Final Result = IF('Table'[Counting] = 2,1,0)

 

If this post helps, then please consider accepting it as the solution to help other members find it more quickly. Thank You!!

View solution in original post

3 REPLIES 3
Kishore_KVN
Super User
Super User

Hello @Anonymous , I am not sure if you are looking for this. I have created three columns so that you can understand clearly. 

Output looks like this:

Kishore_KVN_0-1685538075540.png

 

Three columns DAX will be like this:

Key Column = 'Table'[Task ID]&'Table'[Project ID]
Counting = CALCULATE(COUNT('Table'[Key Column]),ALLEXCEPT('Table','Table'[Key Column]))
Final Result = IF('Table'[Counting] = 2,1,0)

 

If this post helps, then please consider accepting it as the solution to help other members find it more quickly. Thank You!!

ppm1
Solution Sage
Solution Sage

This is doable but not trivial. Also, you'll need an index or some other column (e.g., date) to tell if two rows are consecutive. Do you have that? What do you plan to do with this new column once you have it? There may be a simpler way to get to that result. If this is needed, does it need to be a DAX solution (or could it be done in your query with M)?

 

Pat

Microsoft Employee
Anonymous
Not applicable

Hi ppm1, my end result is to filter out the values which do not meet the criteria. that;s it. I have an index column not a date column, M query if possible. other wish DAX so i can apply it as a filter at Page level

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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