Forum Discussion

jake4001's avatar
jake4001
Frequent Visitor
2 years ago

Calculating rates between date ranges

Hi everyone,

 

I have a dataset showing items in storage between 2 dates and the charges accumulated for them. The charges occur daily: for example for id 1, we paid $25 on 8/30/2023, $25 on 8/31/2023, $25 on 9/1/2023, etc. I want to be able to calculate total rates for any time frame (i.e. by week / month / year - see desired result table). For id 1, $50 would go towards August 2023 and $75 would go towards September 2023. How could I do this in Power BI Desktop? Please share any DAX code as well. Thank you!

 

current table

idshipdatedepartdatecalendardaysdailyratetotalrate
18/30/20239/3/20235$25$125
27/26/20237/30/20235$20$100
36/26/20237/4/202310$30$300

 

desired result

Time PeriodBilledDaysTotalRate
Jun-235$150
Jul-2310$250
Aug-232$50
Sep-233$75

1 Reply

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Icon for Community Champion rankCommunity Champion

    create a date table

    TotalRates = SUMX('YourTable','YourTable'[dailyrate]*COUNTROWS(FILTER(Dates,'Dates'[Date]>='YourTable'[shipdate]&&Dates[Date]<='YourTable'[departdate])))
    BillDays = SUMX('YourTable',COUNTROWS(FILTER(Dates,'Dates'[Date]>='YourTable'[shipdate]&&Dates[Date]<='YourTable'[departdate])))