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
aJ2
Helper I
Helper I

Giving a value to unique id's

I have a table which contains order id's and each order id can have multiple products. 

I want to create a column wherein whenever it encounters the order id, the value 1 is entered into the column else 0 and it also checks the condition if there is only one instance of the order_id.

Below is the screenshot of the sample data.


Capture.PNG

Below is the screenshot of the desired output 

Capture.PNG

Any help is highly appreciated. 

1 ACCEPTED SOLUTION

Hey,

 

here is DAX statement that creates a calculated column

flag = 
var currentOrderID = 'Table1'[order_id]
var minID =
    CALCULATE(
        MIN('Table1'[id])
        ,FILTER(ALL(Table1)
            ,'Table1'[order_id] = currentOrderID
        )
    )
return
IF(AND('Table1'[order_id] = currentOrderID, 'Table1'[id] = minID), 1,0) 

Here is a little screenshot from my tiny sample data 🙂

image.png

 

Hopefully this is what you are looking for

 

Regards

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

5 REPLIES 5
TomMartens
Super User
Super User

Hey,

 

I do not fully understand your requirement, so I try to rephrase what I understand:

 

Flag each row with 1 where the order appears the first time, otherwise flag the row with 0.

 

Given that my understanding is correct, I assume it is also valid to sort the columns by: order_id DESCENDING and id DESCENDING

 

Do you want this be done in the QueryEditor or done by a DAX statement creating a calculated column.

 

Regards

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

You are right. I want to do it using DAX statement

 

Hey,

 

here is DAX statement that creates a calculated column

flag = 
var currentOrderID = 'Table1'[order_id]
var minID =
    CALCULATE(
        MIN('Table1'[id])
        ,FILTER(ALL(Table1)
            ,'Table1'[order_id] = currentOrderID
        )
    )
return
IF(AND('Table1'[order_id] = currentOrderID, 'Table1'[id] = minID), 1,0) 

Here is a little screenshot from my tiny sample data 🙂

image.png

 

Hopefully this is what you are looking for

 

Regards

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Thank you so much Tom. It worked

Your welcome 🙂



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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.