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
Oros
Post Partisan
Post Partisan

Sales: Previous Year's Quarter

Hello.

 

This measure works to get the sales of last year's fiscal year by month.

 

SALES (LY) = CALCULATE(SUM('SALES TABLE'[SALES]),DATESMTD(ENDOFMONTH(dateadd('Calendar'[Date],-12,MONTH))))

 

What would be the correct measure to get the PREVIOUS YEAR's QUARTER sales?  I have a date (calendar table).

 

Thanks.

1 ACCEPTED SOLUTION

Hey no problem! @Oros 

 

Really happy to see such a good use of your date table!

 

All you need to do is change which quarter column we are working with and how we calculate it ( thanks to your great use of the date table )!

 

Providing your fiscal quarter column is text and in the following format "Q1" then use this 😊

 

 

 

 

Prior Year Quarter Sales = 
VAR CurrentDate = TODAY()
VAR CurrentQ = "Q" & IF ( MONTH ( CurrentDate ) >= 10, 1, QUARTER ( EOMONTH ( CurrentDate, 2 ) ) )
VAR PriorYear = IF ( MONTH ( CurrentDate ) >= 10, YEAR ( CurrentDate ) , YEAR ( CurrentDate ) - 1 )
VAR Result =
CALCULATE ( 
    CALCULATE ( SUM ( ‘SALES TABLE’[SALES] ) ),
    FILTER (
        ALL ( ‘Calendar’ ),
        AND (
            QUARTER ( ‘Calendar’[Fiscal Qtr] ) = CurrentQ,
            YEAR ( ‘Calendar’[Fiscal Year] ) = PriorYear
        )
    )
)
RETURN 
Result

 

 

 

 

 

Really appreciate your Kudos!

 

Easy Power BI Tutorials

Unleash the full potential of Power BI with Help Xel

Visit HelpXel

View solution in original post

4 REPLIES 4
helpxel
Regular Visitor

Hey! 

Use this :

 

Prior Year Quarter Sales = 
VAR CurrentDate = TODAY()
VAR CurrentQ = QUARTER( CurrentDate )
VAR PriorYear = YEAR ( CurrentDate ) - 1
VAR Result =
CALCULATE ( 
    CALCULATE ( SUM ( ‘SALES TABLE’[SALES] ) ),
    FILTER (
        ALL ( ‘Calendar’ ),
        AND (
            QUARTER ( ‘Calendar’[Date] ) = CurrentQ,
            YEAR ( ‘Calendar’[Date] ) = PriorYear
        )
    )
)
RETURN 
Result

 

 

 

The measure above wil work perfectly however it would be best practice to seperate out your Sum of Sales measure into a seperate measure and to add a quarter column to your date table.

 

SQLBI has great resources on creating date tables 🙂

 

----------------------------------------------------------------------------------------------------------------------------------

Really appreciate your Kudos!

 

Easy Power BI Tutorials

Unleash the full potential of Power BI with Help Xel

Visit HelpXel

Hi @helpxel 

 

Thank you very much for quick reply.  The numbers from last year's Q does not match.  But it seems that it just needs a minor adjustment.  Our fiscal year starts in November. 

 

What would be the correct way to adjust the measure that you suggested based on our fiscal year?  

 

Q1=Nov. to Jan.

Q2=Feb. to Apr.

Q3=May to Jun.

Q4=July to Oct.

 

Here is my current Calendar Table

Oros_0-1675115129797.png

 

 

Hey no problem! @Oros 

 

Really happy to see such a good use of your date table!

 

All you need to do is change which quarter column we are working with and how we calculate it ( thanks to your great use of the date table )!

 

Providing your fiscal quarter column is text and in the following format "Q1" then use this 😊

 

 

 

 

Prior Year Quarter Sales = 
VAR CurrentDate = TODAY()
VAR CurrentQ = "Q" & IF ( MONTH ( CurrentDate ) >= 10, 1, QUARTER ( EOMONTH ( CurrentDate, 2 ) ) )
VAR PriorYear = IF ( MONTH ( CurrentDate ) >= 10, YEAR ( CurrentDate ) , YEAR ( CurrentDate ) - 1 )
VAR Result =
CALCULATE ( 
    CALCULATE ( SUM ( ‘SALES TABLE’[SALES] ) ),
    FILTER (
        ALL ( ‘Calendar’ ),
        AND (
            QUARTER ( ‘Calendar’[Fiscal Qtr] ) = CurrentQ,
            YEAR ( ‘Calendar’[Fiscal Year] ) = PriorYear
        )
    )
)
RETURN 
Result

 

 

 

 

 

Really appreciate your Kudos!

 

Easy Power BI Tutorials

Unleash the full potential of Power BI with Help Xel

Visit HelpXel

Thanks @helpxel ,

 

It works!

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.