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
YukiK
Impactful Individual
Impactful Individual

Calculate not working for getting Quarter over Quarter values

Hi all,

 

I have a data model that has a fact table containing a measurement like sales amount. I have a calendar table whose grain is month, and the table doesn't have the date, but has relative period/month, quarter, quarter + year, etc.

 

I'm trying to get sales amount last quarter so as to get QoQ %, but the measure I created doesn't seem to work. The fact table is connected is at the month level on "Period" column to the calendar table on "Period" column.

 

I have a sales measure like this.

 

Sales amount = SUM(fact[sales amount])

 

 

And the QoQ measure that I'm trying to work out is like the following.

 

Sales amount last quarter =
VAR __CurrQuarter = MIN(calendar[relative_quarter]) -- unique for each quarter
VAR __SalesLastQuarter = 
    CALCULATE(
        [Sales amount],
        calendar[relative_quarter] = __CurrQuarter  - 1
    )
RETURN
__SalesLastQuarter 

 

 

But this measure only returns blank even though __CurrQuarter - 1 returns the correct values... Any help would be appreciated!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your data model looks like but please try the below.

 

Sales amount last quarter =
VAR __CurrQuarter =
MIN ( calendar[relative_quarter] ) -- unique for each quarter
VAR __SalesLastQuarter =
CALCULATE (
[Sales amount],
FILTER ( ALL ( calendar ), calendar[relative_quarter] = __CurrQuarter - 1 )
)
RETURN
__SalesLastQuarter

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your data model looks like but please try the below.

 

Sales amount last quarter =
VAR __CurrQuarter =
MIN ( calendar[relative_quarter] ) -- unique for each quarter
VAR __SalesLastQuarter =
CALCULATE (
[Sales amount],
FILTER ( ALL ( calendar ), calendar[relative_quarter] = __CurrQuarter - 1 )
)
RETURN
__SalesLastQuarter

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


YukiK
Impactful Individual
Impactful Individual

Okay, this worked! Using "FILTER()" around the condition was the trick. Though I don't fully understand why I needed that for this to work. It was my understanding that the interals would be the same with that of without "FILTER()".

 

Would you mind sharing your wisdom around this concept?

Hi, 

it is quite difficult for me to explain without seeing the model.

Thank you.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


YukiK
Impactful Individual
Impactful Individual

- I have a sales fact table whose grain is per month per row.

- I have a dimention calendar table whose grain is also per month per row.

 

What might be tricky is my calculation is for quarter level data.

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.