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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
GRH87
Frequent Visitor

Defining a primary product based on different order numbers on a sales ticket.

Hi there,

 

Apologies for the longwinded subject line, it was somewhat hard to condense into something that points directly at my issue, so that's what the text below aims to do!

 

So what I'm trying to do is relatively simple in theory, but I'm not quite sure how to implement it.

 

What I'm trying to do:

 

Column 1 = SalesID (could contain multiple items under the same ID) - thus there are duplicate IDs in this field.

Column 2 = ItemOnOrder (this represents the numerical order of the item on the sales order, under the Sales ID)

e.g. Apples = 0, Oranges = 1, Pineapples = 2.

Column 3 = PrimaryProduct The calculated column I want to implement that returns either a 0 or 1. This will define the 'Primary Product' i.e. 1, this will represent the first product on the sales list. Where 0 = primary, and anything that isn't the first on the order, will be marked as '0' i.e. not primary product.

 

Problem:

For the most part most the primary product is defined as 0 on the ItemOnOrder, but sometimes the order will start with a 1 and not a 0.

 

The result in Column 3 (PrimaryProduct) will always be the first number that occurs, either 0 or 1.

 

If the first number within Column 2 (ItemOnOrder) = 0 then Column 3 (PrimaryProduct) value = 1, all the following numbers will give a Column 3 value of 0.

 

If no 0 exists in the rows against Column2 (ItemOnOrder), look for the first number (which will only ever be a 1) in Column 2 then Column 3 value will return a 1, all subsequent numbers after 1 will receive a 0 value.

 

I've been looking at CONTAINS and so forth inside IF statements, but can't get anything solid.

 

Here is some sample data of the results I would expect to see based on the logic/parameters above.

GRH87_1-1612308376592.png

 

Would appreciate some expertise here, it will give me a great boost to my DAX learning.

 

Thanks in advance.

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

if(minx(table,if(table[salesid]=earlier(salesid),table[itemonorder],99999))=table[itemonorder],1,0)

View solution in original post

2 REPLIES 2
wdx223_Daniel
Super User
Super User

if(minx(table,if(table[salesid]=earlier(salesid),table[itemonorder],99999))=table[itemonorder],1,0)

Thank you very much, works a treat. Marked as solution. 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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