Forum Discussion

schaezac's avatar
schaezac
Frequent Visitor
1 year ago
Solved

Aggregation of iterative date-based function

Hi,   I am struggling to figure out how to create a measure to accomplish the calculation I need. Here is my sample data:   Unique ID Branch Date Actual Revenue Actual Cost Actual Profit ...
  • schaezac's avatar
    1 year ago

    I FINALLY figured it out after an entire day of research/learning. Thank you bhanu_gautam for starting me down the right path.

     

    The aggregation issue was solved by defining several variables WITHIN an iterator function, which in this case was a sumx. Here is the final code that worked for me (please note I also had a separate calendar table 'Date' which was connected to the fact table):

     

    FinallyWorkingMeasure = 

     

    VAR md = 

    DATE(year(MAXX(ALLSELECTED('Date'[Date]),'Date'[Date])),month(MAXX(ALLSELECTED('Date'[Date]),'Date'[Date])),1) -- this was just formatting the selected date to match my data which showed first day of each month
     
    RETURN 
     
    sumx('Table',
     
    VAR actualcost = 'Table'[Actual Cost]
    VAR latestmargin = 
    calculate(MAX('Table'[Budget Expected Total Profit Margin %]),ALLEXCEPT('Table','Table'[Unique ID]),'Date'[Date]=md)
     
    RETURN
     
    divide(actualcost, 1 - latestmargin, 0))