Forum Discussion

PaulStokes's avatar
PaulStokes
Frequent Visitor
2 years ago
Solved

DAX - POWER PIVOT measures using date before date

Hello fellow DAX enthusiasts, Help needed please.  I can do this simply in Ms Excel. But I am struggling to write the DAX to have as measures in a Power Pivot in Excel. Sample data below drawn fro...
  • some_bih's avatar
    2 years ago

    Hi PaulStokes possible solution as following

    create 3 different calculated columns as you are calculating amounts based on row level

    Creation order is important to avoid complexity. Output below is the same as your picture

    1. EarlyDate

    =
    VAR __part=MyTable[PART]
    VAR __sup_name=MyTable[SUP_NAME]
    VAR __date=MyTable[DATE]
    RETURN
    CALCULATE(
    MAX(MyTable[DATE]);
    FILTER(MyTable;MyTable[PART]=__part && MyTable[SUP_NAME]=__sup_name && MyTable[DATE]<__date)
    )

    2. EarlyValue

    =VAR __part=MyTable[PART]
    VAR __sup_name=MyTable[SUP_NAME]
    VAR __date_early=MyTable[EarlyDate]
    RETURN
    CALCULATE(
    SUM(MyTable[Cost]);
    FILTER(MyTable;MyTable[PART]=__part && MyTable[SUP_NAME]=__sup_name && MyTable[DATE]=__date_early)
    )

    3.% Change

     

    =
    IF(MyTable[EarlyValue]=BLANK();BLANK();
    MyTable[Cost]/MyTable[EarlyValue]-1)

     

     

     

  • PaulStokes's avatar
    PaulStokes
    2 years ago

    WOW ! BIG Kudos to some_bih for the reply and answer to my question. Resolved 🙂