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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
BudMan512
Helper V
Helper V

Volume lost for 12 months prior to customer loss

@speedramps

 

I am trying to determine the number of Gallons Lost during the 12-month period, prior to the End Date of the Account.

 

There are three tables provided in the data. A link to the data is provided.

Here is the Customer table. The End Date is the date a customer is lost.

BudMan512_0-1706720198593.png

 

 

Each customer has deliveries of fuel that are measured in Gallons.  Some of the deliveries fall within the 12 months prior to the end date and some do not. I need only the gallons that do fall within that time period.

Here is the Sales Table

BudMan512_1-1706720198594.png

 

 

Also included in the data is a Calendar table ranging from 1/1/2022 to 12/31/2024.

One complication with the Calendar Table is that it is used for both the End Date of the customer and elsewhere in the report, for the customer Start Date.

 

In conclusion, I need the sum of Gallons Lost for the 12 months prior to the customer’s End Date.

 

Here is the link to an Excel spreadsheet containing the data tables.

 

https://1drv.ms/x/s!An-c-kQsqoNPglOF0ahWAx-kJHQh?e=uqaV1Q 

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

Hi @BudMan512 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a calculated column on Customer table.

Gallons lost =
VAR _date =
    EDATE ( [End Date], -12 )
RETURN
    CALCULATE (
        SUM ( 'Sales'[Gallons] ),
        FILTER (
            'Sales',
            Sales[Account] = EARLIER ( 'Customer'[Account] )
                && 'Sales'[Delivery Date] >= _date
                && 'Sales'[Delivery Date] <= EARLIER ( 'Customer'[End Date] )
        )
    )

(3) Then the result is as follows.

vtangjiemsft_0-1707114060660.png

vtangjiemsft_1-1707114129441.png

Best Regards,

Neeko Tang

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

10 REPLIES 10
v-tangjie-msft
Community Support
Community Support

Hi @BudMan512 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a calculated column on Customer table.

Gallons lost =
VAR _date =
    EDATE ( [End Date], -12 )
RETURN
    CALCULATE (
        SUM ( 'Sales'[Gallons] ),
        FILTER (
            'Sales',
            Sales[Account] = EARLIER ( 'Customer'[Account] )
                && 'Sales'[Delivery Date] >= _date
                && 'Sales'[Delivery Date] <= EARLIER ( 'Customer'[End Date] )
        )
    )

(3) Then the result is as follows.

vtangjiemsft_0-1707114060660.png

vtangjiemsft_1-1707114129441.png

Best Regards,

Neeko Tang

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

@v-tangjie-msft

Hi Neeko,

I have run into a snag with the provided formula. Results are wrong when there are 2 or more customers with the same end date and the values are duplicated.  Below is a screenshot of the problem.

I wonder if you would mind taking a look at this?

Thanks,

Bud

BudMan512_1-1707403445644.png

 

@v-tangjir-msft

Hi Neeko, this worked perfectly.  Thank you for helping me.

Bud

Thank you Neeko,  I appreciate your help.  I may not be able to try this until tomorrow but I would be happy to mark it as complete.  It looks good, thank you.

speedramps
Super User
Super User

We want to help you but you keep posting links that do not work.

Please ask friend, collegaue or manager to help show you how to share example data exeternally via OneDrive, Dropbox or Sharepoint.

It just wastes your time and our time if you keep sharing broken links. Thank you

speedramps_0-1706723940436.png

 

@speedramps

As I did not hear back from you on this I assume yet another data link bit the dust.  

Even though I couldn't give you the solution on this, I did learn a lot from you about the  process, so thank you for that.

Bud

My apologies,  I tested the link several time and it worked fine.  I will get  one that works.

Hi Bud

I will try take a look tomorrow.

I am unpaid volunteer but like to help 

@speedramps 

Someone else has provided the Solution to my question.

Thank you for the time you invested to help me better understand the process.

I do appreciate it.

Bud

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors