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
MikeMCFRS
Helper III
Helper III

Six Months Before and After Calculation

Hello All,

I am trying to calculate six months cost before and after a month. I reserached the forum and found some good formula below:

6MonthBefore+Calclaute(Sum(****,Datesinperiod(******). I am attaching a screenshot below. The first Six months calculation worked but the 6months after leaves the column empty. Any ideas from the forum will be appreciated:Screenshot (111).png

 

1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

@MikeMCFRS ,

 

LASTDATE() return the last date in your column. If you plus 6 month based on the last date, still return the last date, so the interval date in DATESINPERIOD() function is nothing, so the result is blank. In this senario, you should use FIRSTDATE() instead.

6MonthsBefore =
CALCULATE (
    SUM ( Bill[Gross Charges] ) - SUM ( Bill[Gross Collections] ),
    DATESINPERIOD (
        'Bill'[DOS].[Date],
        FIRSTDATE ( 'Bill'[DOS].[Date] ),
        +6,
        MONTH
    )
)

Community Support Team _ Jimmy Tao

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

3 REPLIES 3
v-yuta-msft
Community Support
Community Support

@MikeMCFRS ,

 

LASTDATE() return the last date in your column. If you plus 6 month based on the last date, still return the last date, so the interval date in DATESINPERIOD() function is nothing, so the result is blank. In this senario, you should use FIRSTDATE() instead.

6MonthsBefore =
CALCULATE (
    SUM ( Bill[Gross Charges] ) - SUM ( Bill[Gross Collections] ),
    DATESINPERIOD (
        'Bill'[DOS].[Date],
        FIRSTDATE ( 'Bill'[DOS].[Date] ),
        +6,
        MONTH
    )
)

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

@Vyk , Hi There, your solution worked great for me. Although I must mention that the "The Before and After cost" did not add up to the total cost in the middle. I will investigate further why this is the case. If you have any ideas feel free to share.

 

Once again. Thanks for your help.

lc_finance
Solution Sage
Solution Sage

Hi @MikeMCFRS ,

 

 

can you share a sample Power BI file with the formula that is not working?

That will make it easier to help you. You can share your sample PBI file using One Drive, Google Drive or another similar tool.

 

Regards

 

LC

Interested in Power BI and DAX tutorials? Check out my blog at www.finance-bi.com

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.

Top Solution Authors