Forum Discussion

OmarSek75's avatar
OmarSek75
Regular Visitor
2 years ago

Measure to filter rows Using another measure DAX

In summary, this measure identifies sales quantities that deviate significantly from the user's average sales within a year for a specific product brand, helping to flag unusual sales patterns.

User Year Decalartion Anomaly =
var UserYearProductMean =
CALCULATE(
    AVERAGE(ft_qualityesod[quantity]),
    ALLEXCEPT(pbidimusers, pbidimusers[username]),
    ALLEXCEPT(DateTable, DateTable[Year]),
    ALLEXCEPT(DimProduct, DimProduct[category], DimProduct[product_line]),
    ft_qualityesod[brand] = "ttm"
)

// User-Year-Product Standard Deviation
var UserYearProductStdDev =
CALCULATE(
    STDEV.P(ft_qualityesod[Quantity]),
    ALLEXCEPT(pbidimusers, pbidimusers[username]),
    ALLEXCEPT(DateTable, DateTable[Year]),
    ALLEXCEPT(DimProduct, DimProduct[category], DimProduct[product_line]),
    ft_qualityesod[brand] = "ttm"
)

// User-Year-Product Anomaly Detection
VAR Quantity = SUM(ft_qualityesod[quantity])
VAR Mean = UserYearProductMean
VAR StandarDeviation = UserYearProductStdDev
VAR Threshold = 1.96 * StandarDeviation
VAR UpperBound = Mean + Threshold
VAR LowerBound = Mean - Threshold
var result =
IF(
     Quantity > UpperBound || Quantity < LowerBound,
    1,
    0
)
RETURN result
---------------------------------------------
This is the result of my measure : 
we have a user name, product_line, category on row, year and month on columns and  the measure  User Year Decalartion Anomaly as value

Based on that measure, I want to create a new measure that uses this result to achieve the following:

The expected output is:
Create a new measure that allows me to get the rows where there is at least one '1' in the first measure.


User name Product line  Category            MeasureValue 
A                  PL                 new                    0 ( I don't have any 1 in the value)
A                  PL                 retread                1 (I have 1 in the month 10 on a year 2023) 
A                  TC                  all                       1 (I have 1 in the month 10 on a year 2023) 

2 Replies