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
kahnailee
Advocate I
Advocate I

Pricing analysis over time - need a change flag/indicator

I'm trying to track any/all price changes over a period of time across multiple suppliers. In doing so, I pivoted the data with the Date in the columns, SKU in the rows, and Cost within the values. That works perfectly for my needs, but I also need a flag that indicates if there's a change in price per SKU/row. I tried doing a MAX minus MIN for each line, which worked, but that wouldn't factor Supplier so it would compare all.

 

Here's a sample of the unpivoted data, with the highlighted portion being what I need to trigger a flag comparing day-over-day changes at both the SKU and Supplier level:

 

2018-11-23_9-36-24.jpg

 

What's the best way of determining a "PriceChangeFlag" by each supplier and sku?

1 ACCEPTED SOLUTION

HI @kahnailee,

 

You can try to use following measure to return tag based on diff between current and previous cost:

Diff Tag=
VAR currDate =
    MAX ( Table3[Date] )
VAR currSKU =
    SELECTEDVALUE ( Table3[Sku] )
VAR currSupplier =
    SELECTEDVALUE ( Table3[Supplier] )
VAR prevDate =
    CALCULATE (
        MAX ( Table3[Date] ),
        FILTER (
            ALLSELECTED ( Table3 ),
            [Date] < currDate
                && [Supplier] = currSupplier
                && [Sku] = currSKU
        )
    )
VAR prevCost =
    CALCULATE (
        MIN ( Table3[Cost] ),
        FILTER (
            ALLSELECTED ( Table3 ),
            [Date] = prevDate
                && [Supplier] = currSupplier
                && [Sku] = currSKU
        )
    )
VAR result =
    IF ( prevCost <> BLANK (), MAX ( Table3[Cost] ) - prevCost, 0 )
RETURN
    IF ( result > 0, "↑", IF ( result < 0, "↓", "-" ) )

In addition, you can also create a calculated column with dynamic hex color code based on diff, then use conditional formatting feature to add color to original field value.

2.PNG

Conditional formatting in tables


Regards,

Xiaoxin Sheng

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

View solution in original post

10 REPLIES 10
Greg_Deckler
Super User
Super User

I'm thinking something like:

 

Measure Flag = 
VAR __date = MAX([Data_Date]) //current date
VAR __sku = MAX([SKU]) //current sku
VAR __supplier = MAX([Supplier]) //current supplier
VAR __prevCostDate = MAXX(FILTER(ALL('Table'),[SKU]=__sku && [Supplier]=__supplier && [Data_Date]<__date),[Data_Date])
VAR __prevCost = MAXX(FILTER(ALL('Table'),[SKU]=__sku && [Supplier]=__supplier && [Data_Date]=__prevCostDate),[Cost])
RETURN
IF([Cost]<>__prevCost,1,0)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

That would work if there was one sku, I believe, but I have thousands. Therefore, I get an error of "a single value for column 'Cost' cannot be determined". Any ideas?

Sorry, missed an aggregation.

 

Measure Flag = 
VAR __date = MAX([Data_Date]) //current date
VAR __sku = MAX([SKU]) //current sku
VAR __supplier = MAX([Supplier]) //current supplier
VAR __prevCostDate = MAXX(FILTER(ALL('Table'),[SKU]=__sku && [Supplier]=__supplier && [Data_Date]<__date),[Data_Date])
VAR __prevCost = MAXX(FILTER(ALL('Table'),[SKU]=__sku && [Supplier]=__supplier && [Data_Date]=__prevCostDate),[Cost])
RETURN
IF(MAX([Cost])<>__prevCost,1,0)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

That works, but it doesn't factor each supplier. Meaning, it will look across all suppliers to see if there's a change overall, not looking at one supplier for the available dates. We're getting close though.

That depends on the context of your visual. If you have a visual setup the way you do in your picture, then it should work. That is why I do a MAX([Supplier]) and then use that in the filters do make sure I am dealing with the correct supplier.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

This is ideally how I'd like to see the data day over day. I'd also like to have the ability to filter out only those in which have changes (outside of those with zero's or blanks).

 

2018-11-23_11-28-13.jpg

 

 

I've also put in a filter for Supplier so that should help reduce the anomalies, but I still need the filterable flag.

HI @kahnailee,

 

You can try to use following measure to return tag based on diff between current and previous cost:

Diff Tag=
VAR currDate =
    MAX ( Table3[Date] )
VAR currSKU =
    SELECTEDVALUE ( Table3[Sku] )
VAR currSupplier =
    SELECTEDVALUE ( Table3[Supplier] )
VAR prevDate =
    CALCULATE (
        MAX ( Table3[Date] ),
        FILTER (
            ALLSELECTED ( Table3 ),
            [Date] < currDate
                && [Supplier] = currSupplier
                && [Sku] = currSKU
        )
    )
VAR prevCost =
    CALCULATE (
        MIN ( Table3[Cost] ),
        FILTER (
            ALLSELECTED ( Table3 ),
            [Date] = prevDate
                && [Supplier] = currSupplier
                && [Sku] = currSKU
        )
    )
VAR result =
    IF ( prevCost <> BLANK (), MAX ( Table3[Cost] ) - prevCost, 0 )
RETURN
    IF ( result > 0, "↑", IF ( result < 0, "↓", "-" ) )

In addition, you can also create a calculated column with dynamic hex color code based on diff, then use conditional formatting feature to add color to original field value.

2.PNG

Conditional formatting in tables


Regards,

Xiaoxin Sheng

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

@Xiaoxin Sheng

 

Wow, that's an interesting solution. Do you happen to have the file you put together from the screenshot? If so, do you mind sharing?

HI @kahnailee,

 

I Just add measure to value field and enable conditional formatting based on calculated column. I attached sample file below.

 

Regards,

Xiaoxin Sheng

 

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

Hi,

 

So will you apply a filter on any one supplier and then see the result?  If you have 500 suppliers, you will have to filter 500 times.  Am i missing something?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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