Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ThangNT
Helper I
Helper I

Calculate Quarterly Data from Cumulative Data

I have three data tables: Date, Accounts, and IncomeStatement. The Income Statement table contains cumulative data for three companies—FPT, HPG, and PNJ—specifically for two accounts: Gross Sales and Deductions. I need to calculate quarterly data for each account and each company based on this semi-annual, nine-month, and annual cumulative data.
I have tried to used SWITCH TRUE function but it doesn't work.

1 ACCEPTED SOLUTION

@ThangNT 

 

if you want to write a measure, you can try this measure:

 

Quarterly_Amount_measure = var prev_Q=calculate(max('Date'[Date Key]) , filter(all('Date'[Date Key]) , 'Date'[Date Key] < selectedvalue('Date'[Date Key])))
return
sum(IncomeStatement[Amount]) - CALCULATE(sum(IncomeStatement[Amount]) , filter(all(IncomeStatement) , IncomeStatement[Date Key]=prev_Q && IncomeStatement[Security Key]=SELECTEDVALUE(IncomeStatement[Security Key]) && IncomeStatement[Account Key] in values(Accounts[Account Key]) && year(IncomeStatement[Date Key])=selectedvalue('Date'[Year]) ))
 
keep in mind that rows and columns in matrix should be selected from Account and Date table.
let me know if this is your expectation.
 
SelvaSalimi_0-1727090247937.png

 

 
If this post helps, then I would appreciate a thumbs up  and mark it as the solution to help the other members find it more quickly. 

View solution in original post

9 REPLIES 9
Selva-Salimi
Solution Specialist
Solution Specialist

Hi @ThangNT 

 

You can write a column in incomestatement table as follows:

 

Quarterly_Amount = var prev_Q=calculate(max(IncomeStatement[Date Key]) , filter(IncomeStatement , IncomeStatement[Date Key] < EARLIER(IncomeStatement[Date Key])))
return
IncomeStatement[Amount] - CALCULATE(max(IncomeStatement[Amount]) , filter(IncomeStatement , IncomeStatement[Date Key]=prev_Q && IncomeStatement[Security Key]=EARLIER(IncomeStatement[Security Key]) && IncomeStatement[Account Key] = EARLIER(IncomeStatement[Account Key])))
 
*let me know is it exactly what you expect to want to reset per year?!
 
If this post helps, then I would appreciate a thumbs up  and mark it as the solution to help the other members find it more quickly. 

I have received the error message "EARLIER/EARLIEST refers to an earlier row context which doesn't exist.".  I want that quarterly amount will be reset per year, meaning that, the second quarter 2015 values will be the semi-annual 2015 values subtracting the first quarter values.
In additonal, I want to use a measure instead of a calculated column.

are you sure that you have created a column, not measure??

When I use your DAX formula for a calculated column, the error message "EARLIER/EARLIEST refers to an earlier row context which doesn't exist." disappears.  However, the quarterly values for 2015 are incorrect.

@ThangNT 

 

if you want to write a measure, you can try this measure:

 

Quarterly_Amount_measure = var prev_Q=calculate(max('Date'[Date Key]) , filter(all('Date'[Date Key]) , 'Date'[Date Key] < selectedvalue('Date'[Date Key])))
return
sum(IncomeStatement[Amount]) - CALCULATE(sum(IncomeStatement[Amount]) , filter(all(IncomeStatement) , IncomeStatement[Date Key]=prev_Q && IncomeStatement[Security Key]=SELECTEDVALUE(IncomeStatement[Security Key]) && IncomeStatement[Account Key] in values(Accounts[Account Key]) && year(IncomeStatement[Date Key])=selectedvalue('Date'[Year]) ))
 
keep in mind that rows and columns in matrix should be selected from Account and Date table.
let me know if this is your expectation.
 
SelvaSalimi_0-1727090247937.png

 

 
If this post helps, then I would appreciate a thumbs up  and mark it as the solution to help the other members find it more quickly. 

It feels like magic! This problem had been getting on my nerves for days, and I truly appreciate your help. Thank you so much again!

ThangNT
Helper I
Helper I

Date KeyYearQuarter
03-31-142014Q1
06-30-142014Q2
09-30-142014Q3
12-31-142014Q4
03-31-152015Q1
06-30-152015Q2
09-30-152015Q3
12-31-152015Q4

 

Account KeyClassSubclass
1Net SalesGross Sales
2Net SalesDeduction
Security KeyIndustry KeyDate KeyAccount KeyAmount
PNJ25504003-31-1412,476,645,830,566
PNJ25504006-30-1414,968,075,298,030
PNJ25504009-30-1417,340,661,939,448
PNJ25504012-31-1419,297,810,872,565
PNJ25504003-31-142-22,954,574,987
PNJ25504006-30-142-43,476,519,121
PNJ25504009-30-142-68,887,703,362
PNJ25504012-31-142-98,592,775,013
PNJ25504003-31-1512,143,708,017,008
PNJ25504006-30-1513,868,684,344,728
PNJ25504009-30-1515,672,524,928,345
PNJ25504012-31-1517,741,445,592,122
PNJ25504003-31-152-6,645,160,137
PNJ25504006-30-152-13,778,057,891
PNJ25504009-30-152-22,386,483,710
PNJ25504012-31-152-33,092,915,485
FPT45103003-31-14110,867,321,675,354
FPT45103006-30-14114,241,494,214,006
FPT45103009-30-14135,029,947,594,626
FPT45103012-31-14132,873,026,689,995
FPT45103003-31-142-49,685,343,347
FPT45103006-30-142-97,644,480,042
FPT45103009-30-142-156,981,881,776
FPT45103012-31-142-228,370,331,060
FPT45103003-31-15132,873,026,689,955
FPT45103006-30-15118,237,232,496,581
FPT45103009-30-15127,966,213,261,357
FPT45103012-31-15138,707,143,264,487
FPT45103003-31-1520
FPT45103006-30-152-267,211,130,394
FPT45103009-30-152-468,728,388,594
FPT45103012-31-152-747,444,508,465
HPG15102003-31-1416,576,317,290,406
HPG15102006-30-14113,338,718,385,687
HPG15102009-30-14119,166,119,243,978
HPG15102012-31-14125,851,816,458,125
HPG15102003-31-142-60,818,402,801
HPG15102006-30-142-141,951,551,508
HPG15102009-30-142-222,492,959,708
HPG15102012-31-142-326,467,635,412
HPG15102003-31-1515,927,283,729,062
HPG15102006-30-1517,740,367,029,589
HPG15102009-30-1516,948,179,608,452
HPG15102012-31-1517,248,728,069,861
HPG15102003-31-152-89,347,814,331
HPG15102006-30-152-92,600,588,468
HPG15102009-30-152-103,122,219,506
HPG15102012-31-152-126,555,700,326
Selva-Salimi
Solution Specialist
Solution Specialist

@ThangNT 

 

would you share dummy samples of your data and your expectations?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.