Forum Discussion

jpc's avatar
jpc
Icon for Helper I rankHelper I
2 years ago
Solved

Power query - build table of cost per day from a list of quotes with start and end dates

I am trying to use powerQuery to build a table of costing information that I can use with a common date table.   I have a table of quotes, with start and end dates. I also have two parameter in pow...
  • jpc's avatar
    jpc
    2 years ago

    ...replying again to my own thread in case it is useful to somebody else

    I extended my use case a bit to make it robust, and hence had to update my DAX
    Other scenarios i wanted to cover - overlapping quotes, and gaps in quotes.  The below addresses all of these now to my satisfaction.

    FirmCost = // the cost strictly according to quotes - is blank if no quote is in range

    VAR __StartDateOfCostToUse = MAXX(FILTER('CostData','CostData'[Start Date]<=MAX('Calendar'[Date]) && 'CostData'[End Date]>=MIN('Calendar'[Date]) ) , 'CostData'[Start Date])  

    RETURN MAXX(FILTER('CostData','CostData'[Start Date]=__StartDateOfCostToUse  ) , 'CostData'[Cost])  // positive match

    and

    SelectedCost =

    VAR __CostInBetween = LASTNONBLANKVALUE(    

            FILTER(        
                ALL('Calendar'[Date]),
                'Calendar'[Date]<=MAX('Calendar'[Date])    
            ),
            [FirmCost]      

        )

    VAR __EarliestStartDate = MIN( CostData[Start Date] )
    VAR __EarliestCost = MAXX(FILTER('CostData','CostData'[Start Date]= __EarliestStartDate)  , 'CostData'[Cost])

    RETURN if(__CostInBetween = BLANK(), __EarliestCost, __CostInBetween )