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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.