Forum Discussion
DAX Calculated Column to identify price deviation
- 4 years ago
The mode is the most frequently occurring value and DAX Patterns gives this general approach:
Mode := MINX ( TOPN ( 1, ADDCOLUMNS ( VALUES ( Data[Value] ), "Frequency", CALCULATE ( COUNT ( Data[Value] ) ) ), [Frequency], 0 ), Data[Value] )This prior post gives further examples of how to apply this:
https://community.powerbi.com/t5/Desktop/Calculating-mode-of-a-measure/m-p/83116Since you don't want the mode over the whole table (just the current product), you'll have to do a bit of additional filtering:
PROMO / OVERPRICE := VAR CurrProduct = Sales[Product] VAR FreqTable = GROUPBY ( FILTER ( Sales, Sales[Product] = CurrProduct ), Sales[Retail Price], "Frequency", SUMX ( CURRENTGROUP (), 1 ) ) VAR Mode = MINX ( TOPN ( 1, FreqTable, [Frequency] ), Sales[Retail Price] ) RETURN SWITCH ( TRUE (), Sales[Retail Price] < Mode, "PROMO", Sales[Retail Price] > Mode, "OVERPRICE" )
The mode is the most frequently occurring value and DAX Patterns gives this general approach:
Mode :=
MINX (
TOPN (
1,
ADDCOLUMNS (
VALUES ( Data[Value] ),
"Frequency", CALCULATE ( COUNT ( Data[Value] ) )
),
[Frequency],
0
),
Data[Value]
)
This prior post gives further examples of how to apply this:
https://community.powerbi.com/t5/Desktop/Calculating-mode-of-a-measure/m-p/83116
Since you don't want the mode over the whole table (just the current product), you'll have to do a bit of additional filtering:
PROMO / OVERPRICE :=
VAR CurrProduct = Sales[Product]
VAR FreqTable =
GROUPBY (
FILTER ( Sales, Sales[Product] = CurrProduct ),
Sales[Retail Price],
"Frequency", SUMX ( CURRENTGROUP (), 1 )
)
VAR Mode =
MINX ( TOPN ( 1, FreqTable, [Frequency] ), Sales[Retail Price] )
RETURN
SWITCH (
TRUE (),
Sales[Retail Price] < Mode, "PROMO",
Sales[Retail Price] > Mode, "OVERPRICE"
)Thank you very much AlexisOlson , I just tested your formula and it works perfectly to meet my needs 🙂