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

Win a FREE 3 Day Ticket to FabCon Vienna. Apply now

Reply
Anonymous
Not applicable

Subtract the Sum of Two Columns based on Preceding and Current Selected Value

I have a Database Table with Columns Quarter and Quantity. Minimizing the actual data with 30K entries, I have simplified it into the table below:

 

QuarterQuantity
2022Q42464
2022Q42525
2023Q15534
2023Q11421
2023Q11351
2023Q13461
2023Q26161
2023Q2124
2023Q2516

 

I have finished the task using multiple DAX, but I want to specifically create a table that will generate/update upon changing only the Quarter Filter. Suppose the selected value in the Quarter Filter is 2023Q2. I want to display a column that shows the difference of the sum of the Quantity of the current selected Quarter (2023Q2) subtracted with the sum of the Quantity of the preceding Quarter (2023Q1).

 

I want the result to be:

Filtered Quarter: 2023Q2

Sum of Quantity

2023Q2 - 2023Q1

6801-1505

 

This is the DAX that I have come up with for Column 2023Q2 - 2023Q1:

 

 

Selected Quarter QuantitySum - Preceding Quarter QuantitySum = 
CALCULATE(
	SUM('Database'[Quantity]),
	'Database'[Quarter] IN { SELECTEDVALUE('Database'[Quarter]) }
	) - CALCULATE(
		SUM('Database'[Quantity]),
		'Database'[Quarter] IN { ---PRECEDING QUARTER--- }
		)

 

 

 

Cheers!

1 ACCEPTED SOLUTION

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Create another column in the table with the first month of each quarter.  Share that revised table.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi Ashish, thanks for your response. Could you please explain why I need to create the said column? I am aiming to accomplish this task by creating only one DAX if it's possible.

QuarterStarting MonthQuantity
2022Q1Januaryxxx
2022Q2Aprilxxx
2022Q3Julyxxx
2022Q4October2464
2022Q4October2525
2023Q1January5534
2023Q1January1421
2023Q1January1351
2023Q1January3461
2023Q2April6161
2023Q2April124
2023Q2April516

 

Hi,

That additional column will allow creation of a Date column.  This in turn will allow creation of a Calendar Table.  We will then be able to use the Date Intelligence functions.  Key in values in place of XXX and share the revised table.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hello,

 

Here is the revised table. 

 

QuarterStarting MonthQuantity
2022Q1January251
2022Q2April3671
2022Q3July6237
2022Q4October2464
2022Q4October2525
2023Q1January5534
2023Q1January1421
2023Q1January1351
2023Q1January3461
2023Q2April6161
2023Q2April124
2023Q2April

516

 

Thanks!

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.