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

previous quarter to date

Hi,

 

I am trying to calculate Current QTD and Previous Quarter's QTD. Current QTD is pretty straight forward but when I try to calculate PQTD I get full previous quarter numbers.

 

Ex: If Current quarter QTD is Q2: 4/1/2018 to 6/6/2018

     then Previous Quarter QTD Q1: 1/1/2018 to 3/6/2018

 

1. Current QTD = Calculate(SUM(Messages Table[Messages_column]),DIM_Date[date])

 

2. Previous Quarter = CALCULATE(SUM(Messages Table[Messages_column]),DATEADD(DIM_Date[date].[Date],-1,QUARTER))

 

3. Previous QTD = CALCULATE([PreviousQuarter],DATESQTD(DIM_Date[date]))

 

Thanks in advance

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Anonymous,

 

First of all the measure you have for QTD is not calculation QTD you should use one of two formulas:

 

Current QTD = Calculate(TOTALQTD(SUM(Table2[Value]);DIM_Date[Date]) )

Current QTD = Calculate(SUM(Table2[Value]);DATESQTD(DIM_Date[Date]) )

Regarding the previous QTD when you use the DATEADD you will get all the all the dates that are in the time frame you have for this case you need to calculate the number of days that have pass over previous quarter and calculate the total for those number of days.

 

Try this measure:

Measure =
VAR Previous_Quarter =
    STARTOFQUARTER ( DATEADD ( DIM_Date[Date]; -1; QUARTER ) )
VAR Previous_Quarter_end =
    ENDOFQUARTER ( DATEADD ( DIM_Date[Date]; -1; QUARTER ) )
VAR Current_Quarter_Start =
    STARTOFQUARTER ( DIM_Date[Date] )
VAR Max_Date =
    MAX ( Table2[Date] )
RETURN
    CALCULATE (
        SUM ( Table2[Value] );
        DIM_Date[Date] >= Previous_Quarter
            && DIM_Date[Date]
                <= IF (
                    Previous_Quarter_end
                        <= Previous_Quarter + DATEDIFF ( Current_Quarter_Start; Max_Date; DAY );
                    Previous_Quarter_end;
                    Previous_Quarter + DATEDIFF ( Current_Quarter_Start; Max_Date; DAY )
                )
    )

This will give you the below result (for my values I have 100 for Q1, 200 Q2, 300 Q3, 400 Q4) as you can see previous quarte is half the value in the quarter.

 qrd.png

 

I also added the PBIX attach so you can play around with the slicer

 

 

Regards

 

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

4 REPLIES 4
MFelix
Super User
Super User

Hi @Anonymous,

 

First of all the measure you have for QTD is not calculation QTD you should use one of two formulas:

 

Current QTD = Calculate(TOTALQTD(SUM(Table2[Value]);DIM_Date[Date]) )

Current QTD = Calculate(SUM(Table2[Value]);DATESQTD(DIM_Date[Date]) )

Regarding the previous QTD when you use the DATEADD you will get all the all the dates that are in the time frame you have for this case you need to calculate the number of days that have pass over previous quarter and calculate the total for those number of days.

 

Try this measure:

Measure =
VAR Previous_Quarter =
    STARTOFQUARTER ( DATEADD ( DIM_Date[Date]; -1; QUARTER ) )
VAR Previous_Quarter_end =
    ENDOFQUARTER ( DATEADD ( DIM_Date[Date]; -1; QUARTER ) )
VAR Current_Quarter_Start =
    STARTOFQUARTER ( DIM_Date[Date] )
VAR Max_Date =
    MAX ( Table2[Date] )
RETURN
    CALCULATE (
        SUM ( Table2[Value] );
        DIM_Date[Date] >= Previous_Quarter
            && DIM_Date[Date]
                <= IF (
                    Previous_Quarter_end
                        <= Previous_Quarter + DATEDIFF ( Current_Quarter_Start; Max_Date; DAY );
                    Previous_Quarter_end;
                    Previous_Quarter + DATEDIFF ( Current_Quarter_Start; Max_Date; DAY )
                )
    )

This will give you the below result (for my values I have 100 for Q1, 200 Q2, 300 Q3, 400 Q4) as you can see previous quarte is half the value in the quarter.

 qrd.png

 

I also added the PBIX attach so you can play around with the slicer

 

 

Regards

 

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Nice.. Thanks so much.. very handy

Anonymous
Not applicable

Hi @MFelix,

 

1. Current QTD measure was a copy paste error Smiley Wink but I did calculate it using DATESQTD function, no worries there. 

 

2. Thanks for the PQTD measure. It is working fine but when I add Quarter from DIM_DATE into the X-axis of the chart PQTD numbers disappear. I am trying to figure out the issue but please take a look at the below screenshots:

 

With and Without Quarter in X-axis:

With Quarter.PNGWithout Quarter.PNG

 

 

Anonymous
Not applicable

Hey @MFelix,

 

I figured it out. Thanks for the help...cheers

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.