Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
tmears
Helper III
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
AnthonyTilley
Solution Sage
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

 

1.png

 

 

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!




View solution in original post

7 REPLIES 7
AnthonyTilley
Solution Sage
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

 

1.png

 

 

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!




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

Mariusz
Community Champion
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.
Mariusz Repczynski

 

@Mariusz , @AnthonyTilley 

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

Hi @jdbuchanan71,

 

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.
Mariusz Repczynski

 

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!




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

ContractAllocation.jpg

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.