Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Counting products above target

I would like to calculate how many products are above or below target? i will put a simple representation of my data model. In my fact table i have the first 5 columns and I calculate 3M Average Sales and calculate the KPI by dividing stock by the average and then multiply by 30 (Stock * 30 / 3M Avg Sales), in this case the KPI is a measure not a calculated column I just added it below for illustration. I also have a target column for each row however I calculate another measure for the weighted average of the target as well based on the sales.

 

 

DateProductIDCustomerStockSales3M Avg SalesKPITarget
Jan-23123CustomerA10193  30
Feb-23123CustomerA9496  30
Mar-23123CustomerA10010698.330.5084730
Apr-23123CustomerA108100100.732.1854330
May-23123CustomerA10198101.329.9013230
Jun-23123CustomerA959296.729.4827630
Jul-23123CustomerA1109595.034.7368430
Jan-23456CustomerA10896  30
Feb-23456CustomerA104100  30
Mar-23456CustomerA929195.728.8501730
Apr-23456CustomerA929595.328.9510530
May-23456CustomerA939192.330.2166130
Jun-23456CustomerA1089493.334.7142930
Jul-23456CustomerA979593.331.1785730

 

My product dimension is as follows: 

ProductIdProductProductDescription
123ABike
456BScooter
789CWheel

 

I have tried two methods but they dont seem to work as expected. 

 

Products Above Target =
-- Used to show the count of products that are above target
IF(ISBLANK(
COUNTX (
    FILTER ( ProductID, [KPI] > [Weighted Target] ),
    Product[ProductID]
)), 0,
COUNTX (
    FILTER ( ProductID, [KPI] > [Weighted Target] ),
    Product[ProductID]
)
)
 
 
Products Above Target =
-- Used to show the count of products that are above target
CALCULATE (
    DISTINCTCOUNT ( FACT[ProductID]),
    FILTER ( FACT, [KPI] > [Weighted Target] )
)
 
Thank you!
  • Anonymous , Try like

     

    Countx(
    FILTER ( Values( FACT[ProductID]),
     [KPI] > [Weighted Target] ) , [ProductID]
    )

     

    for avg better way is

     

    3 Month Avg = CALCULATE(AverageX(Values('Date'[MONTH Year]),calculate(Sum('Table'[Value])))
    ,DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-3,MONTH))

1 Reply

  • Anonymous , Try like

     

    Countx(
    FILTER ( Values( FACT[ProductID]),
     [KPI] > [Weighted Target] ) , [ProductID]
    )

     

    for avg better way is

     

    3 Month Avg = CALCULATE(AverageX(Values('Date'[MONTH Year]),calculate(Sum('Table'[Value])))
    ,DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-3,MONTH))