cancel
Showing results for
Search instead for
Did you mean:
Helper III

## Distribute Revenue across months based upon days in the month

I hope someone can help me, In my data table I have the following

Account, Contract Start Date, Contract end date, amount , number of days in contract, rev per day.

xxx, 1st march 2019, 31st May 2019, 1000, 92, £9.57

Basically we received for example £1000 but i want to allocate the revenue across the 3 months based upon the number of days in each month.  For example

March - 31 days = £336.96

April - 30 days = £326.09

May - 31 days = £336.96

Total £1000

I have a data table and a calender table.  so I think it would be a crossjoin, but just cant quite get it right.  ANy help would be appreciated

Cheers

1 ACCEPTED SOLUTION
Solution Sage

personally i would do this in the query editor

i have attached a link to an example. go into the query editor and click on the table. on the right hand side you will see the steps i took to calculate your desired result as below

PBIX FILE

baics is to calculate your days per total, then calcualte the amount per month, finally create a custom colunm that contains an array of all dates between to the start and end date. and then finally expand this colunm

Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

7 REPLIES 7
Solution Sage

personally i would do this in the query editor

i have attached a link to an example. go into the query editor and click on the table. on the right hand side you will see the steps i took to calculate your desired result as below

PBIX FILE

baics is to calculate your days per total, then calcualte the amount per month, finally create a custom colunm that contains an array of all dates between to the start and end date. and then finally expand this colunm

Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Helper III

thanks Anthony, you are a star this worked perfectly.  Thank you for your help it is very much appriciated

Super User II

Hi @tmears

Please see the attached Query Editor version.

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.

Super User II

Is there a performance concern with doing it in DAX and that is why you use PQ?

Super User II

Most of the time I would do things like expanding dates in Query Editor ( most probably even write a SQL script if applicable, as I could not find functions that achieve this and supports Query Folding at the same time ), mainly for the reasons that @AnthonyTilley  mentioned, however, performance would be one factor as well specially with larger datasets like Employee Start / End dates where you have individuals working for many years.

Having said that I think your DAX solution works very well and its a question of preference and having a choice of solutions.

Best Regards,
Mariusz

Please feel free to connect with me.

Solution Sage

From My point of view its just easier.

I awlays prefer to have the data loaded at the lowest granularity you wish to work at. this way if later in the project you are asked to make an alternative view of the data it is being loaded at the required level already.

because your wanting to calculate at a day level it is best to load all the data at a day level.

Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Super User II

Hello @tmears

The following measure should get you what you are looking for.  In my example the Dates table and the Contracts table are not joined, I just use them as filtering although I do use the Month Year column from the Dates table for the visual.

Please note that I do not use the [days in contract] or [rev per day] from the table, I calculate them in the measure.  It is safer that way, fewer things to possibly be out of alignment.

```Contract Value =
SUMX (
Contracts,
VAR MinDate = FIRSTDATE ( Dates[Date] )
VAR MaxDate = LASTDATE ( Dates[Date] )
VAR ContStart = Contracts[Contract Start]
VAR ContEnd = Contracts[Contract End]
VAR FromDate = MAX ( MinDate, ContStart )
VAR ToDate = MIN ( MaxDate, ContEnd )
VAR DaysInContract = DATEDIFF ( Contracts[Contract Start], Contracts[Contract End], DAY ) +1
VAR DailyValue = DIVIDE ( Contracts[amount],  DaysInContract)
RETURN
IF (
LASTDATE ( Dates[Date] ) < ContStart || FIRSTDATE ( Dates[Date] ) > ContEnd,
BLANK (),
( DATEDIFF ( FromDate, ToDate, DAY ) + 1 ) * DailyValue
)
)```

## Helpful resources

Announcements

#### Happy New Year from Power BI

This is a must watch for a message from Power BI!

#### Check it Out!

Click here to read more about the December 2020 Updates!

#### Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

#### Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors