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
wardy912
Frequent Visitor

Add value to several months

Hi everyone, would anyone be able to help with a DAX calculation for the following?

 

I have a data set showing sales won, split into projects (1 time payments) and contracts (multiple payments across multiple months). I have a 'win date' column and a 'number of months' column.

Any idea how I can get the value of the contracts to show in each month, starting from the win month?

 

wardy912_0-1669110095528.jpeg

 

wardy912_1-1669110095529.jpeg

So need the £6,500 added to November and December.

 

Thanks in advance.

1 ACCEPTED SOLUTION

HI @wardy912,

You can create a calendar table and use its date field and raw table custom field to create a matrix, then you can write measure formula to use current date and customer to lookup records:

formula =
VAR cdate =
    MAX ( 'Calendar'[Date] )
VAR invoiceDate =
    CALCULATE ( MAX ( 'Table'[First Invoice Month] ), VALUES ( 'Table'[Customer] ) )
VAR mVolume =
    CALCULATE (
        MAX ( 'Table'[Number of Months] ) + 0,
        VALUES ( 'Table'[Customer] )
    )
VAR _startDate =
    DATE ( YEAR ( invoiceDate ), MONTH ( invoiceDate ), 1 )
VAR _endDate =
    DATE ( YEAR ( _startDate ), MONTH ( _startDate ) + MAX ( mVolume, 1 ), 1 )
RETURN
    IF (
        cdate >= _startDate
            && cdate < _endDate,
        CALCULATE (
            MAX ( 'Table'[Total Value] ) / MAX ( mVolume, 1 ),
            VALUES ( 'Table'[Customer] )
        )
    )

1.PNG

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @wardy912,

What type of effect did you want to display? Split the 'multiple payments' records to multiple rows with divided values?

You can use the category fields and calendar date fields to create chart, then write a measure formula to use current category value to lookup raw table records if current date are include in the date range(start date + payment month offset) and show the divided results.

In addition, can you please share some dummy data with expected results? I think they will be help us clarify your data structure and test to coding formula:

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi Xiaoxin,

 

Thank you for the quick response.

I have added dummy data with required results as requested.

 

I need to be able to show monthly total revenue from projects and contracts.

The monthly fee of contracts needs to be added to each month required, starting from the first invoice date, continuing accoring to the 'number of months' column.

 

Dummy Data:


CustomerDescriptionMonthly PaymentNumber of MonthsTotal ValueFirst Invoice Month
Customer 1Short Term Contract£6,5002£13,000Nov-22
Customer 2Managed Service Contract£10,00012£120,000Nov-22
Customer 3Project  £100,000Dec-22
Customer 4Short Term Contract£5,0005£25,000Feb-23
Customer 5Managed Service Contract£20,0006£120,000Jan-23

 

Required Result:

 

MonthCustomer 1Customer 2Customer 3Customer 4Customer 5Monthly Total
Nov-22£6,500£10,000   £16,500
Dec-22£6,500£10,000£100,000  £116,500
Jan-23 £10,000  £20,000£30,000
Feb-23 £10,000 £5,000£20,000£35,000
Mar-23 £10,000 £5,000£20,000£35,000
Apr-23 £10,000 £5,000£20,000£35,000
May-23 £10,000 £5,000£20,000£35,000
Jun-23 £10,000 £5,000£20,000£35,000
Jul-23 £10,000   £10,000
Aug-23 £10,000   £10,000
Sep-23 £10,000   £10,000
Oct-23 £10,000   £10,000

 

Data can be downloaded from this link

 

Thank you.

HI @wardy912,

You can create a calendar table and use its date field and raw table custom field to create a matrix, then you can write measure formula to use current date and customer to lookup records:

formula =
VAR cdate =
    MAX ( 'Calendar'[Date] )
VAR invoiceDate =
    CALCULATE ( MAX ( 'Table'[First Invoice Month] ), VALUES ( 'Table'[Customer] ) )
VAR mVolume =
    CALCULATE (
        MAX ( 'Table'[Number of Months] ) + 0,
        VALUES ( 'Table'[Customer] )
    )
VAR _startDate =
    DATE ( YEAR ( invoiceDate ), MONTH ( invoiceDate ), 1 )
VAR _endDate =
    DATE ( YEAR ( _startDate ), MONTH ( _startDate ) + MAX ( mVolume, 1 ), 1 )
RETURN
    IF (
        cdate >= _startDate
            && cdate < _endDate,
        CALCULATE (
            MAX ( 'Table'[Total Value] ) / MAX ( mVolume, 1 ),
            VALUES ( 'Table'[Customer] )
        )
    )

1.PNG

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

That works perfectly, thank you!

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.