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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
MCosta_BI
Frequent Visitor

Rolling 12 months (From Earliest_Use_date) + sum of value

Hello, 

 

I was wondering if anyone can help me with a Dax measure for Rolling 12 months for a commission plan structure. Sales reps are paid based on the rolling 12 months of revenue produced by customers that start on Earliest_use_date that ends 11 months after. 

 

here is the structure

CustomerApproved_dateEarliest_Use_DateR12 months Revenue Monthly Fee Prior to Activation
Maria_1232022-01-012022-05-05Revenue generated from= Start_Month Earliest_Use_Date + 11 monthspaid only if activated
Jose_1242023-02-012023-05-15Revenue generated from= Start_Month Earliest_Use_Date + 11 monthspaid only if activated
Carlos_2112021-07-102022-01-12Revenue generated from= Start_Month Earliest_Use_Date + 11 monthspaid only if activated

 

Totals for each should be as follow

Customers Commissionable total Notes
Maria_123413.00 
Jose_12490.00still to be calculated revenue for months Aug 2023- April 2024
Carlos_211240.00 



Sample file

CustomerRevenue DateTotal Revenue R12 M RevenueMonthly Fee Prior to ActivationCommission Monthly
Maria_1232022-01-3110.00   
Maria_1232022-02-2810.00   
Maria_1232022-03-3110.00   
Maria_1232022-04-3010.00   
Maria_1232022-05-3130.0030.0040.0070.00
Maria_1232022-06-3032.0032.00 32.00
Maria_1232022-07-3135.0035.00 35.00
Maria_1232022-08-3136.0036.00 36.00
Maria_1232022-09-3030.0030.00 30.00
Maria_1232022-10-3130.0030.00 30.00
Maria_1232022-11-3030.0030.00 30.00
Maria_1232022-12-3130.0030.00 30.00
Maria_1232023-01-3130.0030.00 30.00
Maria_1232023-02-2830.0030.00 30.00
Maria_1232023-03-3130.0030.00 30.00
Maria_1232023-04-3030.0030.00 30.00
Maria_1232023-05-3130.00   
Maria_1232023-06-3030.00   
Maria_1232023-07-3130.00   
Maria_1232023-08-3130.00   
Jose_1242023-02-2810.00   
Jose_1242023-03-3110.00   
Jose_1242023-04-3010.00   
Jose_1242023-05-3120.0020.0030.0050.00
Jose_1242023-06-3020.0020.00 20.00
Jose_1242023-07-3120.0020.00 20.00
Carlos_2112021-07-3110.00   
Carlos_2112021-08-3110.00   
Carlos_2112021-09-3010.00   
Carlos_2112021-10-3110.00   
Carlos_2112021-11-3010.00   
Carlos_2112021-12-3110.00   
Carlos_2112022-01-3115.0015.0060.0075.00
Carlos_2112022-02-2815.0015.00 15.00
Carlos_2112022-03-3115.0015.00 15.00
Carlos_2112022-04-3015.0015.00 15.00
Carlos_2112022-05-3115.0015.00 15.00
Carlos_2112022-06-3015.0015.00 15.00
Carlos_2112022-07-3115.0015.00 15.00
Carlos_2112022-08-3115.0015.00 15.00
Carlos_2112022-09-3015.0015.00 15.00
Carlos_2112022-10-3115.0015.00 15.00
Carlos_2112022-11-3015.0015.00 15.00
Carlos_2112022-12-3115.0015.00 15.00
Carlos_2112023-01-3115.00   
Carlos_2112023-02-2815.00   
Carlos_2112023-03-3115.00   
Carlos_2112023-04-3015.00   
Carlos_2112023-05-3115.00   
Carlos_2112023-06-3015.00   
Carlos_2112023-07-3115.00   
1 ACCEPTED SOLUTION

Hi,

Please find attached the PBI file.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

11 REPLIES 11
MCosta_BI
Frequent Visitor

@Ashish_Mathur thank you very much. I don't originally have the column that sums up the "monthly fee prior to activation". I need a Dax for that as well. I am sorry I wasn't clear on my first message. All I have is the columns Customer , Revenue Date and total revenue. 

MCosta_BI_0-1689737938050.png

 

You are welcome.  Then how does one know when the revenue accumulation should start from?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

On my Customer table i have the following three columns: customer, Earliest_Use_Date, Approved_Date

 

So my intention is to use these dates to calculate the rolling 12m of Revenue + Monthly Fee Prior to Activation. 

The rolling 12m :

Start_Date= the month of Earliest_Use_Date 

End_Date = 11 months rolling after Earliest_Use_Date 

 

Monthly Fee Prior to Activation :

Start Date = the month of approved_date

End_Date = the month of Earliest_Use_Date-1

Share the raw data (in a format that can be pasted in an MS Excel file) and this time check your message thoroughly before you post.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

 

I am so sorry @Ashish_Mathur . Your are right! I should have been more clear from start. 

Customer Table

customer_number_Name_Created_date_Approved_date_Earliest_UseActivated ServicesAccountManager_
16217Maria_1232021-12-252022-01-012022-05-05yesJake 
33588Jose_1242022-04-282023-02-012023-05-15yesFrank
28580Carlos_2112021-06-192021-07-102022-01-12yesColin 
24359ABC243812022-04-202022-04-222022-06-16yesColin 
25476ABC254982022-01-092022-04-222022-07-14yesJake 
23265ABC232872022-03-022022-04-07 noLucia

 

 

Transactions Table

customer_number_NameRevenue DateTotal Revenue 
16217Maria_1232022-01-3110.00
16217Maria_1232022-02-2810.00
16217Maria_1232022-03-3110.00
16217Maria_1232022-04-3010.00
16217Maria_1232022-05-3130.00
16217Maria_1232022-06-3032.00
16217Maria_1232022-07-3135.00
16217Maria_1232022-08-3136.00
16217Maria_1232022-09-3030.00
16217Maria_1232022-10-3130.00
16217Maria_1232022-11-3030.00
16217Maria_1232022-12-3130.00
16217Maria_1232023-01-3130.00
16217Maria_1232023-02-2830.00
16217Maria_1232023-03-3130.00
16217Maria_1232023-04-3030.00
16217Maria_1232023-05-3130.00
16217Maria_1232023-06-3030.00
16217Maria_1232023-07-3130.00
16217Maria_1232023-08-3130.00
33588Jose_1242023-02-2810.00
33588Jose_1242023-03-3110.00
33588Jose_1242023-04-3010.00
33588Jose_1242023-05-3120.00
33588Jose_1242023-06-3020.00
33588Jose_1242023-07-3120.00
28580Carlos_2112021-07-3110.00
28580Carlos_2112021-08-3110.00
28580Carlos_2112021-09-3010.00
28580Carlos_2112021-10-3110.00
28580Carlos_2112021-11-3010.00
28580Carlos_2112021-12-3110.00
28580Carlos_2112022-01-3115.00
28580Carlos_2112022-02-2815.00
28580Carlos_2112022-03-3115.00
28580Carlos_2112022-04-3015.00
28580Carlos_2112022-05-3115.00
28580Carlos_2112022-06-3015.00
28580Carlos_2112022-07-3115.00
28580Carlos_2112022-08-3115.00
28580Carlos_2112022-09-3015.00
28580Carlos_2112022-10-3115.00
28580Carlos_2112022-11-3015.00
28580Carlos_2112022-12-3115.00
28580Carlos_2112023-01-3115.00
28580Carlos_2112023-02-2815.00
28580Carlos_2112023-03-3115.00
28580Carlos_2112023-04-3015.00
28580Carlos_2112023-05-3115.00
28580Carlos_2112023-06-3015.00
28580Carlos_2112023-07-3115.00
23265ABC232872022-04-3010.00
23265ABC232872022-05-3110.00
23265ABC232872022-06-3010.00
23265ABC232872022-07-3110.00
23265ABC232872022-08-3110.00
23265ABC232872022-09-3010.00
23265ABC232872022-10-3110.00
23265ABC232872022-11-3010.00
23265ABC232872022-12-3110.00
23265ABC232872023-01-3110.00
23265ABC232872023-02-2810.00
23265ABC232872023-03-3110.00
23265ABC232872023-04-3010.00
23265ABC232872023-05-3110.00
23265ABC232872023-06-3010.00


I have four calendar Dates connected to each specific dates in my customer table. I use them for multiple scenarios of reports. 
for Create Date
for Approved Date
for Earliest Use date 

for Revenue

 

 

 

 

I used these two DAX  below that calculates the Rolling 12 months of Revenue (Rolling starts on Earliest Use Date and counts 12 months after)

** This Dax helped me to achieve the rolling sumed monthly correctly, but for some reason was omiting some values for Year total so I created the next Dax to force it to sum all. 

 

 

Rolling 12 using Activation_date ( commissionable) = 
VAR CurrentDate =
    Max('dCalendar'[Date] )
VAR StartDate = CurrentDate - 365
RETURN
    CALCULATE (
       [Total Revenue excl.Setup (for_commission)],
        REMOVEFILTERS(  'dCalendar (EarliestUse)'[Date] ),
        'dCalendar (EarliestUse)'[Date] > StartDate,
        'dCalendar (EarliestUse)'[Date] <= CurrentDate
    )

 

 

This is calculating the correct values by month and Year.

 

 

m_Rolling 12 months ( Activation) = 
VAR __table = SUMMARIZE('dCalendar',[Date],"__value",[Rolling 12 using Activation_date ( commissionable)])
RETURN
IF(HASONEVALUE('dCalendar'[Date]),[Total Revenue excl.Setup (for_commission)],SUMX(__table,[__value]))

 

 

 

This is how I have data shown by Fiscal Year and month

MCosta_BI_0-1689866757304.png

The problem is that now, the company wants to add any revenue generated by customers before earliest_ use_date. The totals should sum the rolling and the sum of the amount generated prior. The revenue produced before earliest_use date will be summed and paid on the month of earliest_use date + any revenue produced on that month. 
I am breaking my head to achieve this. 

If you cant help, I will understand. I you think there is light to these dark path, please share with me. I will be forever greatfull. 

 

Thanks,

 

Munique

 

Hi,

Based on the 2 tables that you have shared, show the expected result very clearly with an explanation.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

This is my expected results:

 

   2022    2023            2024  
AccountManager_customer_number_NameJanFebMarAprTotalMayJunJulAugSepOctNovDecJanFebMarAprTotalMayJunTotal 
Colin16217Carlos_21175151515120151515151515151515151515180   
Frank23265Jose_124                  502070
Jake28580Maria_123     703235363030303030303030413   
Grand Total  75151515120854750514545454545454545593502070

 

Original table

MCosta_BI_5-1689903646271.png

 

table with formulas below

MCosta_BI_4-1689903589798.png

 

I need to sum the values generated prior to earliest_date on the of activation month.

MCosta_BI_1-1689902843045.png

To look like this :

This should be my end result for all of the headache. 

MCosta_BI_6-1689903728194.png

 

 

The table "Total revenue 12m rolling from Earliest_Use_Date" I used these two formulas ( as mentioned before). 

 

Rolling 12 using Activation_date ( commissionable) = 
VAR CurrentDate =
    Max('dCalendar (Revenue)'[Calendar Date])
VAR StartDate = CurrentDate - 365
RETURN
    CALCULATE (
       [Total Revenue],
        'dCalendar (EarliestUse)'[Calendar Date] > StartDate,
        'dCalendar (EarliestUse)'[Calendar Date] <= CurrentDate
    )
m_Rolling 12 months ( Activation) = 
VAR __table = SUMMARIZE('dCalendar (Revenue)',[Calendar Date],"__value",[Rolling 12 using Activation_date ( commissionable)])
RETURN
IF(HASONEVALUE('dCalendar (Revenue)'[Calendar Date]),[Total Revenue],SUMX(__table,[__value]))

 

 

date table

 

parameters:

Fiscal Start Month 05

Start Year 2019

 

let
 Date = let
Source = List.Dates,
FiscalMonthCalc = 12-#"Fiscal Start Month",
NumberofDays= Duration.Days(DateTime.Date(DateTime.FixedLocalNow())-#date(#"Start Year",1,1)),

// 1. Uncomment this line if you want to get your end date being Today's Date +1 day of the Refresh
#"Invoked FunctionSource" = Source(#date(#"Start Year", 1, 1), NumberofDays+1, #duration(1, 0, 0, 0)),

// 2. Uncomment this line below if you want your end date to be 4 years into the future
//#"Invoked FunctionSource" = Source(#date(#"Start Year", 1, 1), Duration.Days(DateTime.Date(Date.AddDays(Date.EndOfYear(Date.AddYears(DateTime.FixedLocalNow(),+0)),1)) - #date(#"Start Year",1,1)), #duration(1, 0, 0, 0)),

// 3. Uncomment this line if you want to get your end date being the Parameter called "End Year"
//#"Invoked FunctionSource" = Source(#date(#"Start Year", 1, 1), Duration.Days(#date(#"End Year", 12, 30) - #date(#"Start Year",1,1)), #duration(1, 0, 0, 0)),

#"Table from List" = Table.FromList(#"Invoked FunctionSource", Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Added Index" = Table.AddIndexColumn(#"Table from List", "Index", 1, 1),
#"Renamed Columns" = Table.RenameColumns(#"Added Index",{{"Column1", "Date"}}),
#"Added Custom" = Table.AddColumn(#"Renamed Columns", "Year", each Date.Year([Date])),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Month Number", each Date.Month([Date])),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "Day", each Date.Day([Date])),
#"Added Custom3" = Table.AddColumn(#"Added Custom2", "Day Name", each Date.ToText([Date],"ddd")),
#"Added Custom4" = Table.AddColumn(#"Added Custom3", "Month Name", each Date.ToText([Date],"MMM")),
#"Reordered Columns" = Table.ReorderColumns(#"Added Custom4",{"Date", "Index", "Year", "Month Number", "Month Name", "Day", "Day Name"}),
#"Added Custom5" = Table.AddColumn(#"Reordered Columns", "Quarter Number", each Date.QuarterOfYear([Date])),
#"Duplicated Column" = Table.DuplicateColumn(#"Added Custom5", "Year", "Copy of Year"),
#"Renamed Columns1" = Table.RenameColumns(#"Duplicated Column",{{"Copy of Year", "Short Year"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns1",{{"Short Year", type text}}),
#"Split Column by Position" = Table.SplitColumn(#"Changed Type","Short Year",Splitter.SplitTextByRepeatedLengths(2),{"Short Year.1", "Short Year.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Position",{{"Short Year.1", Int64.Type}, {"Short Year.2", Int64.Type}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Short Year.1"}),
#"Renamed Columns2" = Table.RenameColumns(#"Removed Columns",{{"Short Year.2", "Short Year"}}),
#"Added Custom6" = Table.AddColumn(#"Renamed Columns2", "Quarter Year", each Number.ToText([Short Year]) & "Q" & Number.ToText([Quarter Number],"00")),
#"Reordered Columns1" = Table.ReorderColumns(#"Added Custom6",{"Index", "Date", "Day", "Day Name", "Month Number", "Month Name", "Quarter Number", "Quarter Year", "Short Year", "Year"}),
#"Changed Type2" = Table.TransformColumnTypes(#"Reordered Columns1",{{"Date", type date}, {"Day", Int64.Type}, {"Index", Int64.Type}, {"Month Number", Int64.Type}, {"Quarter Number", Int64.Type}, {"Month Name", type text}, {"Quarter Year", type text}, {"Year", Int64.Type}}),
 #"Added Conditional Column" = Table.AddColumn(#"Changed Type2", "Fiscal Year", each if [Month Number] < #"Fiscal Start Month" then [Year] else [Year]+1 ),
 #"Added Conditional Column1" = Table.AddColumn(#"Added Conditional Column", "Fiscal Month", each if [Month Number] < #"Fiscal Start Month" then [Month Name] else [Month Name] ),
 #"Added Custom7" = Table.AddColumn(#"Added Conditional Column1", "Fiscal Month Sort Order", each Number.Mod(Date.Month([Date])+FiscalMonthCalc ,12)+1),
 #"Added Conditional Column3" = Table.AddColumn(#"Added Custom7", "Fiscal Quarter", each if [Fiscal Month Sort Order] >= 1 and [Fiscal Month Sort Order] <= 3 then "Q1"
 else if [Fiscal Month Sort Order] >= 4 and [Fiscal Month Sort Order] <= 6 then "Q2"
 else if [Fiscal Month Sort Order] >= 7 and [Fiscal Month Sort Order] <= 9 then "Q3"
 else if [Fiscal Month Sort Order] >= 10 and [Fiscal Month Sort Order] <= 12 then "Q4"
 else "Q Unknown" ),
#"Added Conditional Column4" = Table.AddColumn(#"Added Conditional Column3", "Fiscal Quarter Sort Number", each if [Fiscal Month Sort Order] >= 1 and [Fiscal Month Sort Order] <= 3 then "1"
 else if [Fiscal Month Sort Order] >= 4 and [Fiscal Month Sort Order] <= 6 then "2"
 else if [Fiscal Month Sort Order] >= 7 and [Fiscal Month Sort Order] <= 9 then "3"
 else if [Fiscal Month Sort Order] >= 10 and [Fiscal Month Sort Order] <= 12 then "4"
 else "Q Unknown" ),
 #"Changed Type3" = Table.TransformColumnTypes(#"Added Conditional Column4",{{"Fiscal Quarter Sort Number", Int64.Type}, {"Fiscal Month Sort Order", Int64.Type}, {"Fiscal Year", Int64.Type}}),
 #"Renamed Columns3" = Table.RenameColumns(#"Changed Type3",{{"Date", "Calendar Date"}, {"Month Number", "Calendar Month Number"}, {"Month Name", "Calendar Month Name"}, {"Quarter Number", "Calendar Quarter Number"}, {"Quarter Year", "Calendar Quarter Year"}, {"Short Year", "Calendar Short Year"}, {"Year", "Calendar Year"}})

in
 #"Renamed Columns3"
in
    Date

 

MCosta_BI_7-1689903819088.png

 

 

MCosta_BI_8-1689903875696.png

 

 

 

Hi,

Please find attached the PBI file.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I am very thankful for your work, time and generosity. Thank you very much. You are a great human being. It works great!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ashish_Mathur
Super User
Super User

Hi,

Please find attached my solution file.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Europe Fabric Conference

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.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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