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

calculate sales in base of month term

Hello,

 

I am writing because I've been working on solve this problems for many days.  The issue is I have a list of customers and every customer has a term month date, this mean that for customer 1 the sales period is from january to december(term 12), customer 2 the sales period is from july to last day of june, finally customer 3 has september his sales period wil be from october to the last day of september.

 

If I am in the year 2020:

 

sales period of customer 1 will be january 2020 to december 2020

sales period for customer 2 wil be july 2020 to december 2020

sales period for customer 3 wil be October 2020 to december 2020

 

Also the complexity is I have to control this with the year and month selector that make imposible to get the correct result. For example if I select the month october customer one have calculate sales from january to october, customer 2 sales from july to october and customer 3 sales only from october

 

CustomerIDTerm (month number)Sales Last YearSales Current Year
112  
26  
39  

 

Sales table is a simple table by month and customer id.

 

CustomerIDDate Amount 
101/01/2019                        1,374
101/02/2019                        3,918
101/03/2019                        7,109
101/04/2019                        1,777
101/05/2019                        7,307
101/06/2019                            217
101/07/2019                        1,763
101/08/2019                            368

 

the result is calculate the sales in base of term period for the last year and the current year. Only care the current year because the last year can be a complete value that I can calculate in a calculate column 🙂

 

Hope i explain good, any doubts let me know 

 

https://www.dropbox.com/s/k6pnvkkpgkc2q5o/data%20sales.zip?dl=0 

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

Hi @Anonymous ,

 

Would you please try the following two measure :

 

Sales CY =
SWITCH (
    MAX ( Data[CustomerID] ),
    1,
        CALCULATE (
            SUM ( Sales[Amount] ),
            DATESBETWEEN (
                'Date'[Date],
                DATE ( YEAR ( TODAY () ), 1, 1 ),
                MAX ( 'Date'[Date] )
            )
        ),
    2,
        CALCULATE (
            SUM ( Sales[Amount] ),
            DATESBETWEEN (
                'Date'[Date],
                DATE ( YEAR ( TODAY () ), 6, 30 ),
                MAX ( 'Date'[Date] )
            )
        ),
    3,
        CALCULATE (
            SUM ( Sales[Amount] ),
            DATESBETWEEN (
                'Date'[Date],
                DATE ( YEAR ( TODAY () ), 9, 30 ),
                MAX ( 'Date'[Date] )
            )
        )
)



Sales LY =
SWITCH (
    MAX ( Data[CustomerID] ),
    1,
        CALCULATE (
            SUM ( Sales[Amount] ),
            SAMEPERIODLASTYEAR (
                DATESBETWEEN (
                    'Date'[Date],
                    DATE ( YEAR ( TODAY () ), 1, 1 ),
                    MAX ( 'Date'[Date] )
                )
            )
        ),
    2,
        CALCULATE (
            SUM ( Sales[Amount] ),
            SAMEPERIODLASTYEAR (
                DATESBETWEEN (
                    'Date'[Date],
                    DATE ( YEAR ( TODAY () ), 6, 30 ),
                    MAX ( 'Date'[Date] )
                )
            )
        ),
    3,
        CALCULATE (
            SUM ( Sales[Amount] ),
            SAMEPERIODLASTYEAR (
                DATESBETWEEN (
                    'Date'[Date],
                    DATE ( YEAR ( TODAY () ), 9, 30 ),
                    MAX ( 'Date'[Date] )
                )
            )
        )
)

 

Capture4.PNG

 

For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EYff9aeBNTRKgaDn9c4jk5wB9eKqYMxxSEYhtUUxcemVjA?e=VTE1Et

 

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

 

Best Regards,

Dedmon Dai

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

thanks!! 😄

v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

Would you please try the following two measure :

 

Sales CY =
SWITCH (
    MAX ( Data[CustomerID] ),
    1,
        CALCULATE (
            SUM ( Sales[Amount] ),
            DATESBETWEEN (
                'Date'[Date],
                DATE ( YEAR ( TODAY () ), 1, 1 ),
                MAX ( 'Date'[Date] )
            )
        ),
    2,
        CALCULATE (
            SUM ( Sales[Amount] ),
            DATESBETWEEN (
                'Date'[Date],
                DATE ( YEAR ( TODAY () ), 6, 30 ),
                MAX ( 'Date'[Date] )
            )
        ),
    3,
        CALCULATE (
            SUM ( Sales[Amount] ),
            DATESBETWEEN (
                'Date'[Date],
                DATE ( YEAR ( TODAY () ), 9, 30 ),
                MAX ( 'Date'[Date] )
            )
        )
)



Sales LY =
SWITCH (
    MAX ( Data[CustomerID] ),
    1,
        CALCULATE (
            SUM ( Sales[Amount] ),
            SAMEPERIODLASTYEAR (
                DATESBETWEEN (
                    'Date'[Date],
                    DATE ( YEAR ( TODAY () ), 1, 1 ),
                    MAX ( 'Date'[Date] )
                )
            )
        ),
    2,
        CALCULATE (
            SUM ( Sales[Amount] ),
            SAMEPERIODLASTYEAR (
                DATESBETWEEN (
                    'Date'[Date],
                    DATE ( YEAR ( TODAY () ), 6, 30 ),
                    MAX ( 'Date'[Date] )
                )
            )
        ),
    3,
        CALCULATE (
            SUM ( Sales[Amount] ),
            SAMEPERIODLASTYEAR (
                DATESBETWEEN (
                    'Date'[Date],
                    DATE ( YEAR ( TODAY () ), 9, 30 ),
                    MAX ( 'Date'[Date] )
                )
            )
        )
)

 

Capture4.PNG

 

For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EYff9aeBNTRKgaDn9c4jk5wB9eKqYMxxSEYhtUUxcemVjA?e=VTE1Et

 

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

 

Best Regards,

Dedmon Dai

Anonymous
Not applicable

Thanks so much !! @v-deddai1-msft 🙂

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.