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

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
Anonymous
Not applicable


@Anonymous 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
Anonymous
Not applicable


@Anonymous 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

 

Mariusz
Community Champion
Community Champion

Hi @Anonymous 

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.

Anonymous
Not applicable


@Mariusz wrote:

Hi @Anonymous 

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.

parry2k
Super User
Super User

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



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable


@parry2k wrote:

@Anonymouslook 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.

@Anonymous clearly not sure what you are asking here. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.