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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculating Monthly Accrued Revenue Based on Annual Amounts

I am calculating accrued revenue based on annual contract periods and values. Is there an easy way to transform a contract table in M or create a new calculated table in DAX where each contract have been split into monthly contract periods ranging from the annual period start to period end, and allocating the corresponding monthly value per month?

 

Example input table from ERP-system

ContractIdPeriod StartPeriod EndPeriod ValueValue per day
101.01.201931.12.2019100                    0,27
215.02.201914.02.2020100                    0,27
315.03.201915.09.2019100                    0,54
401.06.201901.12.2019100                    0,54
512.08.201912.02.2020100                    0,54
615.08.201915.02.2020100                    0,54

 

Example of desired output: accrued revenue table

ContractIdMonthPeriod StartPeriod EndPeriod Value
10101.01.201931.01.2019          8,49
10201.02.201928.02.2019          7,67
10301.03.201931.03.2019          8,49
10401.04.201930.04.2019          8,22
10501.05.201931.05.2019          8,49
10601.06.201930.06.2019          8,22
10701.07.201931.07.2019          8,49
10801.08.201931.08.2019          8,49
10901.09.201930.09.2019          8,22
11001.10.201931.10.2019          8,49
11101.11.201930.11.2019          8,22
11201.12.201931.12.2019          8,49
1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Anonymous 

 

You may take a look at the post below.

https://community.powerbi.com/t5/Developer/Dax-Help-Create-table-with-variable-of-lines-according-to...

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@Anonymous 

 

You may take a look at the post below.

https://community.powerbi.com/t5/Developer/Dax-Help-Create-table-with-variable-of-lines-according-to...

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks @v-chuncz-msft for the help, the approach with GENERATE() plus some additional code allowed me to create the table I needed. Of course the real problem is a bit more complicated than the simplified example I used in the questions, so this is how I used GENERATE to solve the issue:

 

My end goal was to estimate future states of our contracts and create a time series of accrued contract revenue from this estimate. Summarizing this table provides the accounted (booked) revenue in accordance to the accounting principles used in our firm.

Starting tables:


Contract Headers

ContractIdPeriod StartPeriod EndExpires OnPeriod Length (Months)
101.01.201931.12.2019null12
215.02.201914.02.202014.08.202012
315.03.201915.09.2019null6
401.06.201901.12.2019null6
512.08.201912.02.202012.10.20206
615.08.201915.02.2020null6

 

Contract Lines

ContractDetailIdPeriod Value
1-150
1-225
1-325
2-150
2-250
......

 

Step 1: Creating the base table
In the query I merged the Contract Headers and Contract Lines in order to get one table with all contract lines with contract periods. Calculated value per day from the contract periods.

 

Step 2: Calculate number of future renewals of the contracts

Calculated the number of contract renewals each contract can have in 6 calendar years. Then generated a series of renewal rounds from 0 (current contract state) to the maximum number of renewals for the shortest contract period (monthly contracts).

GENERATESERIES(
    0;
    72;
    1
)

 

Step 3: Generate a new table crossjoining each row from Step 1 with each row from Step 2

GENERATE(
   Output Table from Step1;
   Output Table from Step2
)

This code gave me a new table with where each row in the contract table was crossjoined with each of the round numbers from Step 2. The table contained appr. 1,3 million rows.

 

Step 4: Calculating the future dates of renewals per contract per renewal round

I used SELECTCOLUMN() to create a new table from the output of Step 3 and to add two calculated columns calculating Period Start and Period End per renewal round.

SELECTCOLUMNS(
   Output table from Step 3;
   ...
   // added all the existing columns from the tables
   ...
   "Current Round Period Start";
   EDATE(
      [Period Start];
      [Period Length (Months)] * [Renewal Round Number]
   );
   "Current Round Period End";
   EDATE(
      [Period End];
      [Period Length (Months)] * [Renewal Round Number]
   )
)

 

Step 5: Generate a new table crossjoining the output table from Step 3 with a calendar table generated in-memory

This is the step directly using the DAX code from https://community.powerbi.com/t5/Developer/Dax-Help-Create-table-with-variable-of-lines-according-to...

VAR calendar = CALENDARAUTO()

Return

GENERATE(
   Output Table from Step 4;
   FILTER(
      calendar;
      [Date] >= [Current Round Period Start] && [Date] <= [Current Round Period End]
   )
)

End result:

a table with a time series of values and periods from Today and 5 years in the future (30M+ rows)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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