Molia
Molia

Reputation: 311

QoQ Measures in Power BI

I am looking to do a QoQ calculation in a table. The problem I am facing is that I do not know how to calculate the previous value while the current value also shows. I would then use that field to create a difference or % difference. Hopefully the following example makes it clear.

Sample data:

Quarter |   Year    |Product|   Measure
Q1/19   |   2018    |   A   |   22
Q1/19   |   2018    |   B   |   61
Q1/19   |   2018    |   C   |   187
Q2/19   |   2018    |   A   |   121
Q2/19   |   2018    |   B   |   31
Q2/19   |   2018    |   C   |   15
Q3/19   |   2018    |   A   |   68
Q3/19   |   2018    |   B   |   200
Q3/19   |   2018    |   C   |   75
Q4/19   |   2018    |   A   |   123
Q4/19   |   2018    |   B   |   86
Q4/19   |   2018    |   C   |   153
Q1/19   |   2019    |   A   |   30
Q1/19   |   2019    |   B   |   131
Q1/19   |   2019    |   C   |   178
Q2/19   |   2019    |   A   |   168
Q2/19   |   2019    |   B   |   138
Q2/19   |   2019    |   C   |   87
Q3/19   |   2019    |   A   |   56
Q3/19   |   2019    |   B   |   15
Q3/19   |   2019    |   C   |   88
Q4/19   |   2019    |   A   |   96
Q4/19   |   2019    |   B   |   173
Q4/19   |   2019    |   C   |   76 

Desired Output:
It would be something like below

enter image description here

Attempts:
I tried the following formula as per the link below but it is not working
link: https://community.powerbi.com/t5/Desktop/How-to-add-previous-row-value-with-current-one-and-then-keep/td-p/493467

Previous Value = CALCULATE(SUM('Sheet1'[Measure]), 
FILTER(Sheet1,Sheet1[Quarter]<=EARLIER('Sheet1'[Quarter])))

I would use the PREVIOUSQUARTER function in Power bi but then I believe I would have to convert quarter into date AND the quarter that I need to use is not the same as the calendar quarter

Upvotes: 1

Views: 1970

Answers (1)

Jelle Hoekstra
Jelle Hoekstra

Reputation: 672

The first thing I'd do is try to create ordinality in your quarters. Right now you only list quarters with the post-fix /19 but I can imagine you meant to have /18 as well? In that case I would advice to put the year first and then your quarter as that will result in the right order when sorting alphabetically. E.g. Q1/19 comes before Q2/18 when sorted alphabetically now, while 18/Q2 would be sorted correctly before 19/Q1.

Although you can do you request in a single measure I'd recommend using a calculated column and a measure so it remains easy to understand.

First you create a grouped index column (calculated column). This will create groups for each quarter and will sort them alphabetically adding an index number.

gIndex = RANKX( SUMMARIZE( 'Sheet1' ; 'Sheet1'[Quarter] ) ; 'Sheet1'[Quarter] ; ; ASC )

Then you can use the following (measure) to create the timeshifted quarter total

Previous Q = 

CALCULATE (
    SUM ( 'Sheet1'[Measure] ) ; 
    FILTER ( 
        ALLSELECTED ( 'Sheet1' ) ;
        'Sheet1'[gIndex] = MAX ( 'Sheet1'[gIndex] ) - 1
    )
)

Upvotes: 1

Related Questions