cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Need to create a measure to calculate the sales for the last 12 months.

Have a Power BI model that contains the following tables:
Sales11 (Sales_ID, DateID, sales_amount)
Date11 (DateID, Date, Month, week, Year)
The tables have a relationship. Date is marked as a date table in the Power BI model.
You need to create a measure to calculate the sales for the last 12 months.

Which DAX formula should you use?
1. CALCULATEx(SUM(sales11[sales_amount]) DATESYTD (‘Date11’ [Date]))
2. CALCULATE(SUM(sales11[sales_amount]), SAMEPERIODLASTYEAR (‘Date11’ [Date]))
3. SUM(sales11[sales_amount])-CALCULATE(SUM(sales11[sales_amount]),SAMEPERIODLASTYEAR(‘Date11’[Date]))
4. SUM(sales11[sales_amount])-CALCULATE(SUM(sales11[sales_amount]),DATESYTD(‘Date11’[Date]))

 

Which one is correct 3 or 2? and explain why?

 

At one Place I found 2 is correct and at another place 3 is correct..

Got confused. Please help

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Need to create a measure to calculate the sales for the last 12 months.


@ShivendooKumar wrote:

Have a Power BI model that contains the following tables:
Sales11 (Sales_ID, DateID, sales_amount)
Date11 (DateID, Date, Month, week, Year)
The tables have a relationship. Date is marked as a date table in the Power BI model.
You need to create a measure to calculate the sales for the last 12 months.

Which DAX formula should you use?
1. CALCULATEx(SUM(sales11[sales_amount]) DATESYTD (‘Date11’ [Date]))
2. CALCULATE(SUM(sales11[sales_amount]), SAMEPERIODLASTYEAR (‘Date11’ [Date]))
3. SUM(sales11[sales_amount])-CALCULATE(SUM(sales11[sales_amount]),SAMEPERIODLASTYEAR(‘Date11’[Date]))
4. SUM(sales11[sales_amount])-CALCULATE(SUM(sales11[sales_amount]),DATESYTD(‘Date11’[Date]))

 

Which one is correct 3 or 2? and explain why?

 

At one Place I found 2 is correct and at another place 3 is correct..

Got confused. Please help


I tested this and correct ans is SUM(sales11[sales_amount])-CALCULATE(SUM(sales11[sales_amount]),SAMEPERIODLASTYEAR(‘Date11’[Date]))

 

I have 3 years of sales data.

2013, 2014, 2015

 

Total sales= 15000 (sum of 3 years sales)

2013 Sales=4000

2014 Sales=5000

2015 Sales=6000

 

 

SUM(sales11[sales_amount]) Returns=15000

and CALCULATE(SUM(sales11[sales_amount]),SAMEPERIODLASTYEAR(‘Date11’[Date])) returns =9000

So

SUM(sales11[sales_amount])-CALCULATE(SUM(sales11[sales_amount]),SAMEPERIODLASTYEAR(‘Date11’[Date]))=15000-9000=6000

 

View solution in original post

6 REPLIES 6
Super User
Super User

Re: Need to create a measure to calculate the sales for the last 12 months.

@ShivendooKumar look at this post which gives you last 12 months sum






Did I answer your question? Mark my post as a solution.

Proud to be a Datanaut! Appreciate your Kudos Smiley Happy
Feel free to email me with any of your BI needs.





Super User
Super User

Re: Need to create a measure to calculate the sales for the last 12 months.

Hi @ShivendooKumar 

You can use the below

Sales Rolling 12 months = 
CALCULATE(
    [Sales],
    DATESINPERIOD(
        'Calendar'[Date],
        MIN('Calendar'[Date]) -1,  
        -12,
        MONTH
    )
)

Regards,
Mariusz

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

Re: Need to create a measure to calculate the sales for the last 12 months.


@Mariusz wrote:

Hi @ShivendooKumar 

You can use the below

Sales Rolling 12 months = 
CALCULATE(
    [Sales],
    DATESINPERIOD(
        'Calendar'[Date],
        MIN('Calendar'[Date]) -1,  
        -12,
        MONTH
    )
)

Regards,
Mariusz

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


Thanks for your response. 

 

This is a mockup question and need to select an ans from given list. Would you please provide your ans from given options?

 

Thanks again.

Re: Need to create a measure to calculate the sales for the last 12 months.


@parry2k wrote:

@ShivendooKumarlook at this post which gives you last 12 months sum


Thanks for your response. 

 

This is a mockup question and need to select an ans from given list. Would you please provide your ans from given options?

 

Thanks again.

Super User
Super User

Re: Need to create a measure to calculate the sales for the last 12 months.

@ShivendooKumar clearly not sure what you are asking here. 






Did I answer your question? Mark my post as a solution.

Proud to be a Datanaut! Appreciate your Kudos Smiley Happy
Feel free to email me with any of your BI needs.





Re: Need to create a measure to calculate the sales for the last 12 months.


@ShivendooKumar wrote:

Have a Power BI model that contains the following tables:
Sales11 (Sales_ID, DateID, sales_amount)
Date11 (DateID, Date, Month, week, Year)
The tables have a relationship. Date is marked as a date table in the Power BI model.
You need to create a measure to calculate the sales for the last 12 months.

Which DAX formula should you use?
1. CALCULATEx(SUM(sales11[sales_amount]) DATESYTD (‘Date11’ [Date]))
2. CALCULATE(SUM(sales11[sales_amount]), SAMEPERIODLASTYEAR (‘Date11’ [Date]))
3. SUM(sales11[sales_amount])-CALCULATE(SUM(sales11[sales_amount]),SAMEPERIODLASTYEAR(‘Date11’[Date]))
4. SUM(sales11[sales_amount])-CALCULATE(SUM(sales11[sales_amount]),DATESYTD(‘Date11’[Date]))

 

Which one is correct 3 or 2? and explain why?

 

At one Place I found 2 is correct and at another place 3 is correct..

Got confused. Please help


I tested this and correct ans is SUM(sales11[sales_amount])-CALCULATE(SUM(sales11[sales_amount]),SAMEPERIODLASTYEAR(‘Date11’[Date]))

 

I have 3 years of sales data.

2013, 2014, 2015

 

Total sales= 15000 (sum of 3 years sales)

2013 Sales=4000

2014 Sales=5000

2015 Sales=6000

 

 

SUM(sales11[sales_amount]) Returns=15000

and CALCULATE(SUM(sales11[sales_amount]),SAMEPERIODLASTYEAR(‘Date11’[Date])) returns =9000

So

SUM(sales11[sales_amount])-CALCULATE(SUM(sales11[sales_amount]),SAMEPERIODLASTYEAR(‘Date11’[Date]))=15000-9000=6000

 

View solution in original post

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 57 members 1,047 guests
Please welcome our newest community members: