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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DIACHROMA
Helper II
Helper II

DAX Calculated Column to identify price deviation

Hello everyone,

 

I need help identifying price deviations in my sales table.

In fact I would like to find a way to determine if a sale has been the subject of a promotion or on the contrary if the sale price is higher than usual.

 

Here is an example of what I would like to see:

 

ProductRetail PricePROMO / OVERPRICE
A10 
A10 
A10 
A10 
A5PROMO 
A5PROMO
   
B20 
B20 
B25OVERPRICE
B20 
B20 
B10PROMO
B10PROMO

 

 

I need this to be done in a calculated column to be able to use the "Promo / Overprice" column in a slicer.

 

I thought about creating a formula that identifies the most redundant price for each product and comparing the sales prices against that price.

 

But I have no idea of the syntax of my measurement to bring out the price that comes up most often by product.

 

Someone can help me ? Thanks in advance !!!


Pauline

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

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"
    )

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @DIACHROMA,

Did AlexisOlson 's suggestions help with your scenario? if that is the case, you can consider Kudo or accept his suggestions to help others who faced similar requirements.

If that also doesn't help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
AlexisOlson
Super User
Super User

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 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors