cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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

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

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

Community Champion

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

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

Community Champion

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.

Proud to be a Super User!

Super User

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
)
)```

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors