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
BItoken
Helper III
Helper III

Calculate last 4 Q cummulative Sum of sales

Hi guys,

 

I have last 12 Qtrs in my Power BI report and i have to add a column to show last 4 quarters cummulative sum 

For example i need

Sum of FY19-Q1,Q2,Q3,Q4 at FY-19Q4

Sum of FY19-Q2,Q3,Q4,FY20-Q1 at FY20-Q1

Sum of FY19 Q3,Q4,FY20-Q1,Q2 at FY20-Q2

and so on

 

Any help is much appreciated

 

 

 

6 REPLIES 6
amitchandak
Super User
Super User

@BItoken , Make sure you move Qtr to new table, or it is in your date table.

Create a Rank on QTR

 

Qtr Rank = RANKX(All(Date), Date[FY QTR],,asc,dense)

Try like


Avg last 4 QTR =
calculate(Average(Table[sales]),filter(Date, Date[Qtr Rank]>= Max(Date[Qtr Rank])-4 && Date[Qtr Rank]<=max(Date[Qtr Rank])))

 

If you have date

Rolling 4 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-4,QUARTER))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

I get this error when i try to create a rank on the Qtr number or the FYQ column

 

A single value for column 'fiscalQ' in table 'TABLE' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

Any Suggestions @amitchandak 

Hi @BItoken ,

 

Has your problem been solved?

Is this what you want?

f6.PNGf7.PNG

You can refer to this formula.

Measure = 
CALCULATE(
    SUM(Sheet1[Sales]),
    FILTER(
        ALLSELECTED(Sheet1),
        Sheet1[Index] <= SELECTEDVALUE(Sheet1[Index]) 
    )
)

If not, please give me a sample data model and tell me what effect you want to get.

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

 

 

Hi @v-lionel-msft 

Thanks for your reply

My Desired output is as below. Your logic gets me the rolling sum for all the quarters

I need the sum for last 4 qtrs and then reset for every next qtr

Trailing 12 Months.png

Hi @BItoken ,

 

Try to do like this:

1. Add a [Index] column in "Edit Queries";

2. Create a measure;

Measure = 
VAR x = 
CALCULATE(
    SUM(Sheet1[Sales]),
    FILTER(
        ALL(Sheet1),
        Sheet1[Index]<= SELECTEDVALUE(Sheet1[Index]) && Sheet1[Index] >= SELECTEDVALUE(Sheet1[Index]) - 3 
    )
)
RETURN
IF(
    SELECTEDVALUE(Sheet1[Index]) in {1, 2, 3},
    BLANK(),
    x
)

k1.PNG

My sample data comes from the same table. If your columns come from different tables, the formula will change.

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

I have the Date and FYQ in the same table and FY 21 Q1 is our current Qtr started Apr 1 2020.

I tried this and i think it will not work 
Quarter Rank = RANKX(all('QTR'),'QTR'[fiscalqtd],,ASC,Dense)
My FY data set is like this below.
Fiscalqtd.png

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.