cancel
Showing results for
Did you mean:
Highlighted
Member

## 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..

1 ACCEPTED SOLUTION

Accepted Solutions
Member

## 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..

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

6 REPLIES 6
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

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

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.

Member

## 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.

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.

Member

## 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

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

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

@ShivendooKumar clearly not sure what you are asking here.

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

Member

## 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..

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

Announcements

#### Back to School Contest

Engage and empower students with Power BI!

#### Watch Sessions On Demand!

Continue your learning in our online communities.

#### Summit Australia 2019

Travel to Melbourne and network with thousands of peers!

#### PBI Community Highlights

Check out what's new in the Power BI Community!

Top Ideas
Top Kudoed Authors
Users Online
Currently online: 380 members 3,405 guests
Recent signins: