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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
johnsimpson
New Member

Calculating a KPI where unique order ID's, when identical, are considered a count of 1

We are a Fulfillment business.  I have Sales Data, and I'm having trouble making some determinations within PowerPivot.

 

I am a novice user of PowerBI. Right now, I have a data set from Netsuite, it is raw data row-by-row and not grouped in anyway.  4 rows of data could contain values associated to the same order.  For example:

 

Order IDDateSKUSales RepValueDemand Data Captured?
SO12349/1/2022SKU123Rep A$5000
SO12349/1/2022SKU124Rep A$2000
SO12349/1/2022SKU134Rep A$3001
SO12349/1/2022SKU155Rep A$4000
SO12449/1/2022SKU156Rep B$5000
SO12449/1/2022SKU1656Rep B$2000
SO12449/1/2022SKU987Rep B$3001
SO12449/1/2022SKU193Rep B$4001
SO12449/1/2022SKU144Rep B$2000

 

I want to create a calculation where, if an order has any "1" in the demand column - it is counted as one (even if multiple lines of an order have more than one 1, as is the case with SO1244) and the total is then divided by the total count of orders. This would mean I'd need to somehow have SO1244, although 5 lines of product, counted as one order instead of 5.

 

I hope this makes sense. I think I might need to do something with hierarchies first?

 

Ultimately, then I can say:

 

In September, Rep A entered 100 orders, and of those, x% had demand data captured.  In other words, without grouping by order#, I can certainly already say that % of lines/products had demand data (lines/SKU with demand = 1 divided by total lines) but this is an unhelpful statistic.

 

Any tips appreciated!

John

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @johnsimpson ,

 

Here are the steps you can follow:

1. In Power Query -- Add Column – Index Column – From 1.

vyangliumsft_0-1671504790338.png

2. Create calculated column.

Flag =
var _contain1=SELECTCOLUMNS(FILTER(ALL('Table'),'Table'[Order ID]=EARLIER('Table'[Order ID])),"1",[Demand Data Captured?])
var _min=MINX(FILTER(ALL('Table'),'Table'[Order ID]=EARLIER('Table'[Order ID])),[Index])
return
IF(
   1 in _contain1  && 'Table'[Index]=_min,1,
   IF(
       NOT(1) in _contain1,1,0)
)
KPI =
var _group=SUMX(FILTER(ALL('Table'),'Table'[Order ID]=EARLIER('Table'[Order ID])),[Flag])
var _allgroup=SUMX(ALL('Table'),[Flag])
return
divide(_group,_allgroup)

3. Result:

vyangliumsft_1-1671504790340.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi  @johnsimpson ,

 

Here are the steps you can follow:

1. In Power Query -- Add Column – Index Column – From 1.

vyangliumsft_0-1671504790338.png

2. Create calculated column.

Flag =
var _contain1=SELECTCOLUMNS(FILTER(ALL('Table'),'Table'[Order ID]=EARLIER('Table'[Order ID])),"1",[Demand Data Captured?])
var _min=MINX(FILTER(ALL('Table'),'Table'[Order ID]=EARLIER('Table'[Order ID])),[Index])
return
IF(
   1 in _contain1  && 'Table'[Index]=_min,1,
   IF(
       NOT(1) in _contain1,1,0)
)
KPI =
var _group=SUMX(FILTER(ALL('Table'),'Table'[Order ID]=EARLIER('Table'[Order ID])),[Flag])
var _allgroup=SUMX(ALL('Table'),[Flag])
return
divide(_group,_allgroup)

3. Result:

vyangliumsft_1-1671504790340.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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