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
john-paul
Frequent Visitor

Occurence number or rank for calculated column

Hi,

 

Hoping someone can help me add a calculated column that ranks or counts occurrence number of a Product Id within a Region based on the order number.

 

Where there are multiple instances of the Product Id sold within a Region, then the earliest Order is ranked or counted 1st.

 

Thanks.

 

RegionProduct IdOrderSalesExpected Value
North9011000011001
North9011000021002
North9021000031201
North9021000041202
North9021000051203
West9011000061001
West9021000071201
West9021000081202
West9031000091301
West9031000101302
East9011000111001
East9011000121002
East9011000131003
East9021000141201
East9031000151301
East9031000161302
South9011000171001
South9011000181002
South9011000191003
South9011000201004
South9011000211005
South9031000221301

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Create new column as 

column = CALCULATE(count(Table1[Order]);FILTER(Table1;Table1[Region]=EARLIER(Table1[Region])&&Table1[Product Id]=EARLIER(Table1[Product Id])&&Table1[Order]<=EARLIER(Table1[Order])))


I hope it works for you

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Create new column as 

column = CALCULATE(count(Table1[Order]);FILTER(Table1;Table1[Region]=EARLIER(Table1[Region])&&Table1[Product Id]=EARLIER(Table1[Product Id])&&Table1[Order]<=EARLIER(Table1[Order])))


I hope it works for you

 

Thank you alsasloren.

That is awesome it worked perfectly!

 

Can the formula also be modified as a measure?

Anonymous
Not applicable

Hi @john-paul 
Please check the below code.

Measure = CALCULATE(
COUNT(Table1[Order]);
FILTER(ALL(Table1);
SUMX(FILTER(Table1;EARLIER(Table1[Region])=Table1[Region]);Table1[Column])&&
SUMX(FILTER(Table1;EARLIER(Table1[Product Id])=Table1[Product Id]);Table1[Column])&&
SUMX(FILTER(Table1;EARLIER(Table1[order])<=Table1[Order]);Table1[Column])
)
)

Thanks again alsasloren for the quick response.

 

I wasn't able to get this one to work. I changed each of the Table1[Column] references to Region, Poduct Id and Order.

Do I need to have these inside another function?

 

Anonymous
Not applicable

Hi again I forgot to declare column content.

 

Actually it wasn't so important but i have to create it. just create new column and give a value as 1

 

Like;
column = 1

 

 

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.