0

Dynamic “initial price” driven by a user-selected date filter

How do I calculate a dynamic “initial price” driven by a user-selected date filter?

Background

I have a receiving ledger with a few million rows of receiving entries. Each row contains the usual fields:

·         Purchase order number

·         Part number

·         Received date

·         Unit price

·         Received quantity (QTY)

Goal

I want to track price changes for each part and the resulting dollar impact over a user-selected time period. In the discovery, the user picks a start period and an end period based on the Received date.

How the calculation should work

The base (initial) price is the first price paid for a given part on or after the selected start period. Any later price change is shown as a delta from that initial price:

Price difference = Current price − Initial price

The dollar impact is then weighted by the received quantity:

$ Impact = Received QTY × Price difference

What I’ve tried

I can build every calculation without trouble except for selecting the initial price based on the user’s filter selection. Using a Lag or a previous member approach does not reproduce the result I’m after, because the initial price needs to be anchored to the first record within the selected window rather than the immediately preceding row.  Moreover, it should consider any other filter in the discover, such as the Part number selected.

My question

How can I create a variable initial price that is driven by the date range the user selects on a filter — i.e., the first unit price per part within the chosen start/end period — so the delta and impact recalculate as the filter changes?

 

Thank you 

DG

6 replies

null
    • Redeemed from the Dark Side (Power BI)
    • Obee1
    • 4 days ago
    • Reported - view

    I believe this will work:

    In the semantic/data modeler in "Model", right click on the "initial price" column and change the metric to "First child." 

    Redeploy the model and it should be done.

    • Customer Solutions Architect
    • Moshe_Yossef
    • yesterday
    • Reported - view

    Hi  

    Notice: I have attached the data set and a PIE file with all relevant items – models, formulates, discoveries, etc. So you can try it yourself. 

    Before we start, let’s create a model that has a hierarchy of dates (Year – Quarter –Month Date) with relevant data (see attached with data set). 

    Let’s Explain in words what it is we want to achieve: 

    • select a period 

    • find the earliest date in this period in which an item was sold 

    • set this as the base price for comparisons. 

    • Create a calculation that measures growth compared with that base price 

    Let’s break it into steps: 

    select a period

    This quite literally implies that we need a  Parameter in the Sale Date Hierarchy to choose from. Let’s create it: 

    (call it Base Period)

    find the earliest date in this period in which an item was sold:

    Let's break this even further down: 

    We need to find all the dates in the parameter, where the current item was sold, or in PQL: 

    NonEmpty(
          LeafDescendants([PriceDrift].^[PriceDrift Date Hierarchy].@[Parameter uuid])
          ,([PriceDrift].[PartName].currentmember,[measures].[PriceDrift UnitPrice])
    )

     

    The LeafDescensants() function will return all the dates of the selected parameter. 

    The nonempty() will only return dates that have a Unit Price. 

    The [PriceDrift].[PartName].currentmember ensures the set is evaluated for each part seperately. 

    Next, we want the first of these dates – that's done using the First Element() function: 

    FirstElement(
    NonEmpty(
         LeafDescendants([PriceDrift].^[PriceDrift Date Hierarchy].@[Parameter uuid])
         ,([PriceDrift].[PartName].currentmember,[measures].[PriceDrift UnitPrice]))
    )
    

    Next, we want to create a data point of the above with the unit price measure: 

    (
    FirstElement(
    NonEmpty(
         LeafDescendants([PriceDrift].^[PriceDrift Date Hierarchy].@[Parameter uuid])
         ,([PriceDrift].[PartName].currentmember,[measures].[PriceDrift UnitPrice]))
    ),
    [measures].[PriceDrift UnitPrice]
    )
    

    This will be our Base Price Measure – be sure to use the measures in the context. 

    Create a calculation that measures growth compared with that base price

    That’s straight forward – unit price – base price: 

     

     

    Let’s call that “Price Drift” 

    Create Discovers 

    Now we can create a discover showing base price, unit price, and price drift. 

    Once we select Base Price – The parameter will appear in the discover. 

    Next we can use a multi select tree slicer to select the periods that will be shown in the discover, and of course a filter for the parts, to receive: 

     

    Or we can put the part on the rows to receive a matrix: 

     

    This works well just notice the matrix creates A lot of queries, so depending on how much data you have you will want to be careful with it. 

    Also – Avoid multi select filter for the parts – as the CurrentMember will not work with multiple selections.

      • NPANS
      • yesterday
      • Reported - view

       how does this technique compare to the prior suggestion from  ?

      • Customer Solutions Architect
      • Moshe_Yossef
      • yesterday
      • Reported - view

       This approach works and the calculation is explicit.

      When I tried  's idea it didn't quite work, we're looking into it. 

      • Customer Solutions Architect
      • Moshe_Yossef
      • 8 hrs ago
      • Reported - view

       
      Ok I went in deeper - the point is that FirstChild Aggregation in the model does not work in context - so If you choose Jan 2025 and Part 004 - it will check for Jan 1st 2025, and if part 004 wasn't sold on that date at all - you'll get an empty result.

      Second - If you use a unit price with an average aggregation - FirstChild will always do a sum (which you can fix by using sales / quantity).

      • NPANS
      • 2 hrs ago
      • Reported - view

       

      From what I can see, First Child finds the first instance in the data for the item for the given selection.  It has nothing explicitly to do with dates. You'll get an empty result if part 04 wasn't sold in January 2025 at all. This is the correct result. If it was sold on Jan 28th, then that's the first item that shows up.

      Second, the unit price in this example should be as described: first price / first qty. I'm not sure an average is the right answer at all (what are you averaging over if it's the first item?)

      Last, the approach should be a lot more performant and flexible, operating without a date hierarchy.

Content aside

  • 1 hr agoLast active
  • 6Replies
  • 85Views
  • 4 Following