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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
hugo_barbara
Helper I
Helper I

Measure that calculates the difference between calls and adds this difference in the next month

Hey, guys! Can you help me? I need to create a measure that calculates the difference between tickets opened and closed within a month and this difference is added to the tickets opened in the following month. When this difference is negative or zero, it will not be carried over to the next month.


Example:

hugo_barbara_0-1708003258003.png

 

I tried to create some measurements but without success, follow my line of reasoning:

DifferenceCallsAccumulated =
VAR CurrentDate = MAX(dCalendario[Date])
VAR NextMonth = EOMONTH(CurrentDate, 1)

// Calculate the difference between opened and closed calls for the current month
VAR CurrentMonthDifference =
CALCULATE(
[Quantity of Task Created] - [Quantity of Tasks Closed],
YEAR(fto_incidents_ptk[Opened On - Calendar]) = YEAR(CurrentDate) &&
MONTH(fto_incidents_ptk[Opened On - Calendar]) = MONTH(CurrentDate)
)

// Calculate the difference between opened and closed calls for the next month
VAR NextMonthDifference =
CALCULATE(
[Quantity of Task Created],
YEAR(fto_incidents_ptk[Opened On - Calendar]) = YEAR(NextMonth) &&
MONTH(fto_incidents_ptk[Opened On - Calendar]) = MONTH(NextMonth)
) -
CALCULATE(
[Quantity of Tasks Closed],
YEAR(fto_incidents_ptk[Closed On - Calendar]) = YEAR(NextMonth) &&
MONTH(fto_incidents_ptk[Closed On - Calendar]) = MONTH(NextMonth)
)

RETURN
IF(
NextMonthDifference > 0,
CurrentMonthDifference + NextMonthDifference,
CurrentMonthDifference
)



1 ACCEPTED SOLUTION
talespin
Solution Sage
Solution Sage

hi @hugo_barbara 

 

Please check if this is what you want, I hope you understand what you are doing. Your difference is now incorrect.

 

The Logic used for New Tickets and Closed Tickets

Open Ticket = Ticket with Open date in selected month is counted as open, irrespective of its status.

Closed Ticket = Ticket with a closed date in selected month.

 

STEP1 : Create this data model, I have one date table linked to your table on both date columns, keep CreateDate as active and ClosedDate as inactive and both relationship as Single, one(CALENDAR) to many(Data Table). Please change column and table names accordingly.

 

talespin_2-1708053195433.png

 

STEP2 Create these four measures.

--------------------------------------------------------------------------------------
Closed Tickets = CALCULATE( COUNT(Tickets[Task]), USERELATIONSHIP('CALENDAR'[Date], Tickets[Closed At]) )
-------------------------------------------------------------------------------------- 
Difference = [NewTickets] - [Closed Tickets]
-------------------------------------------------------------------------------------- 
NewTickets = CALCULATE( COUNT(Tickets[Task]) )
 --------------------------------------------------------------------------------------
Modify New Tickets =
VAR _Year = SELECTEDVALUE('CALENDAR'[YEAR])
VAR _mth = SELECTEDVALUE('CALENDAR'[MonthNo])
VAR _dt = EDATE(DATE(_Year, _mth, 1), -1)
VAR _prevValYear = YEAR(_dt)
VAR _prevValMth = MONTH(_dt)
VAR _prevMthNewTickets = CALCULATE( COUNT(Tickets[Task]), REMOVEFILTERS('CALENDAR'), 'CALENDAR'[YEAR] = _prevValYear, 'CALENDAR'[MonthNo] = _prevValMth )
VAR _prevMthClosedTickets = CALCULATE( COUNT(Tickets[Task]), REMOVEFILTERS('CALENDAR'), USERELATIONSHIP('CALENDAR'[Date], Tickets[Closed At]), 'CALENDAR'[YEAR] = _prevValYear && 'CALENDAR'[MonthNo] = _prevValMth )
VAR currMthNewTickets = CALCULATE( COUNT(Tickets[Task]) )
VAR _Diff = (_prevMthNewTickets - _prevMthClosedTickets)

RETURN currMthNewTickets + IF(_Diff > 0, _Diff, BLANK())
 --------------------------------------------------------------------------------------

 

STEP3 Now as you see in screenshot, please these measures in same order. Change the Column color to hide the correct open ticket count column(Change color to white or whatever matches your background).

 

talespin_1-1708052872805.png

 

View solution in original post

5 REPLIES 5
talespin
Solution Sage
Solution Sage

hi @hugo_barbara 

 

Please check if this is what you want, I hope you understand what you are doing. Your difference is now incorrect.

 

The Logic used for New Tickets and Closed Tickets

Open Ticket = Ticket with Open date in selected month is counted as open, irrespective of its status.

Closed Ticket = Ticket with a closed date in selected month.

 

STEP1 : Create this data model, I have one date table linked to your table on both date columns, keep CreateDate as active and ClosedDate as inactive and both relationship as Single, one(CALENDAR) to many(Data Table). Please change column and table names accordingly.

 

talespin_2-1708053195433.png

 

STEP2 Create these four measures.

--------------------------------------------------------------------------------------
Closed Tickets = CALCULATE( COUNT(Tickets[Task]), USERELATIONSHIP('CALENDAR'[Date], Tickets[Closed At]) )
-------------------------------------------------------------------------------------- 
Difference = [NewTickets] - [Closed Tickets]
-------------------------------------------------------------------------------------- 
NewTickets = CALCULATE( COUNT(Tickets[Task]) )
 --------------------------------------------------------------------------------------
Modify New Tickets =
VAR _Year = SELECTEDVALUE('CALENDAR'[YEAR])
VAR _mth = SELECTEDVALUE('CALENDAR'[MonthNo])
VAR _dt = EDATE(DATE(_Year, _mth, 1), -1)
VAR _prevValYear = YEAR(_dt)
VAR _prevValMth = MONTH(_dt)
VAR _prevMthNewTickets = CALCULATE( COUNT(Tickets[Task]), REMOVEFILTERS('CALENDAR'), 'CALENDAR'[YEAR] = _prevValYear, 'CALENDAR'[MonthNo] = _prevValMth )
VAR _prevMthClosedTickets = CALCULATE( COUNT(Tickets[Task]), REMOVEFILTERS('CALENDAR'), USERELATIONSHIP('CALENDAR'[Date], Tickets[Closed At]), 'CALENDAR'[YEAR] = _prevValYear && 'CALENDAR'[MonthNo] = _prevValMth )
VAR currMthNewTickets = CALCULATE( COUNT(Tickets[Task]) )
VAR _Diff = (_prevMthNewTickets - _prevMthClosedTickets)

RETURN currMthNewTickets + IF(_Diff > 0, _Diff, BLANK())
 --------------------------------------------------------------------------------------

 

STEP3 Now as you see in screenshot, please these measures in same order. Change the Column color to hide the correct open ticket count column(Change color to white or whatever matches your background).

 

talespin_1-1708052872805.png

 

@talespin Thank you very much!! It worked out!!!!

hi @hugo_barbara 

 

You're welcome.

talespin
Solution Sage
Solution Sage

hi @hugo_barbara 

 

Can you please share sample data or pbix file with all sensitive data removed.

hi @talespin here is an example of the data I use when I need help..

tks

Created AtClosed AtTaskState
19/12/2023 09:35 task0510560Backlog
25/01/2024 15:27 task0522824Backlog
08/01/2024 10:51 task0515841Backlog
04/01/2024 12:09 task0514727Backlog
11/01/2024 17:55 task0517696Backlog
22/01/2024 09:53 task0521663Backlog
22/01/2024 16:09 task0521777Backlog
22/01/2024 16:27 task0521786Backlog
22/01/2024 17:52 task0521802Backlog
25/01/2024 14:29 task0522808Backlog
29/01/2024 15:52 task0524232Backlog
31/01/2024 11:26 task0524979Backlog
02/02/2024 11:28 task0525766Backlog
07/02/2024 15:50 task0528089Backlog
08/02/2024 11:44 task0528436Backlog
08/02/2024 14:57 task0528524Backlog
08/02/2024 17:25 task0528597Backlog
31/01/2024 15:10 task0525048Backlog
01/02/2024 17:07 task0525523Backlog
14/02/2024 16:11 task0530067Backlog
09/01/2024 19:20 task0516798Backlog
07/02/2024 15:28 task0528080Backlog
13/02/2024 13:46 task0529738Backlog
14/02/2024 16:31 task0530076Backlog
14/02/2024 17:21 task0530088Backlog
04/12/2023 09:37 task0505040Backlog
09/01/2024 15:59 task0516721Backlog
10/01/2024 07:46 task0516908Backlog
17/01/2024 15:41 task0520344Backlog
01/02/2024 17:38 task0525532Backlog
06/02/2024 12:23 task0527424Backlog
01/11/2023 15:0501/11/2023task0490702Canceled
05/02/2024 13:5305/02/2024task0526892Canceled
14/02/2024 17:2614/02/2024task0530091Canceled
05/02/2024 14:0005/02/2024task0526897Canceled
28/09/2023 11:3128/09/2023task0478953Canceled
24/03/2023 14:4731/03/2023task0410886Closed
28/03/2023 11:2906/04/2023task0411778Closed
10/04/2023 17:2418/05/2023task0415738Closed
13/04/2023 09:5408/05/2023task0416944Closed
13/04/2023 09:5708/05/2023task0416945Closed
13/04/2023 17:0921/08/2023task0417098Closed
18/04/2023 11:1818/05/2023task0418528Closed
24/04/2023 15:2627/07/2023task0424056Closed
25/04/2023 11:5829/05/2023task0424712Closed
26/04/2023 18:5123/05/2023task0426680Closed
26/04/2023 19:1218/05/2023task0426691Closed
27/04/2023 15:0705/05/2023task0426975Closed
27/04/2023 17:4105/05/2023task0427041Closed
28/04/2023 09:3805/05/2023task0427355Closed
28/04/2023 10:0111/09/2023task0427363Closed
28/04/2023 11:2205/05/2023task0427420Closed
07/05/2023 21:1629/05/2023task0429784Closed
08/05/2023 17:2315/05/2023task0430104Closed
10/05/2023 17:2119/05/2023task0430831Closed
15/05/2023 18:4814/08/2023task0432248Closed
17/05/2023 20:2927/07/2023task0433056Closed
18/05/2023 19:0020/06/2023task0433609Closed
19/05/2023 11:1017/08/2023task0434283Closed
22/05/2023 11:0315/08/2023task0436603Closed
23/05/2023 11:5929/05/2023task0437197Closed
01/06/2023 15:4717/08/2023task0440733Closed
01/06/2023 18:2414/07/2023task0440772Closed
06/06/2023 15:2314/07/2023task0442217Closed
07/06/2023 14:3012/09/2023task0442540Closed
22/06/2023 11:1319/07/2023task0447210Closed
03/07/2023 17:2421/07/2023task0450441Closed
05/07/2023 12:4812/07/2023task0450993Closed
06/07/2023 18:3819/07/2023task0451556Closed
13/07/2023 17:4519/07/2023task0454120Closed
09/08/2023 18:3517/08/2023task0463329Closed
11/08/2023 15:3615/08/2023task0464197Closed
21/08/2023 16:3711/09/2023task0467658Closed
22/08/2023 13:5330/01/2024task0467908Closed
22/08/2023 15:2516/11/2023task0467941Closed
04/10/2023 17:0122/11/2023task0482022Closed
06/10/2023 16:5707/12/2023task0482856Closed
09/10/2023 10:5930/10/2023task0483514Closed
09/10/2023 16:4822/11/2023task0483651Closed
17/10/2023 13:3824/10/2023task0485481Closed
23/10/2023 10:1224/11/2023task0486772Closed
25/10/2023 09:5501/11/2023task0487602Closed
01/11/2023 17:5024/11/2023task0490802Closed
06/11/2023 17:3721/11/2023task0492658Closed
14/11/2023 14:3521/11/2023task0495646Closed
14/11/2023 14:4221/11/2023task0495652Closed
14/11/2023 15:0219/12/2023task0495668Closed
14/11/2023 15:1021/11/2023task0495673Closed
16/11/2023 15:1007/12/2023task0496318Closed
16/11/2023 15:3220/12/2023task0496341Closed
21/11/2023 16:2407/12/2023task0498564Closed
24/11/2023 15:0708/12/2023task0501294Closed
27/11/2023 18:3107/12/2023task0502321Closed
27/11/2023 18:4214/12/2023task0502325Closed
28/11/2023 19:2119/12/2023task0502785Closed
01/12/2023 12:0407/12/2023task0504046Closed
05/12/2023 11:0211/12/2023task0505683Closed
05/12/2023 16:1931/01/2024task0505811Closed
22/01/2024 14:0508/02/2024task0521729Closed
25/01/2024 09:1808/02/2024task0522644Closed
29/01/2024 15:1601/02/2024task0524215Closed
31/01/2024 15:5008/02/2024task0525071Closed
16/03/2023 10:1627/03/2023task0408468Closed
23/03/2023 10:3325/04/2023task0410456Closed
24/03/2023 12:5417/08/2023task0410850Closed
28/03/2023 10:1625/04/2023task0411749Closed
04/04/2023 14:4208/05/2023task0414032Closed
17/04/2023 10:4908/05/2023task0418093Closed
19/12/2023 13:4005/02/2024task0510618Closed
21/03/2023 19:1806/04/2023task0409940Closed
07/05/2023 15:5521/08/2023task0429760Closed
17/07/2023 14:0214/08/2023task0455159Closed
24/07/2023 14:0817/08/2023task0457783Closed
26/07/2023 13:5615/08/2023task0458456Closed
28/07/2023 08:5231/08/2023task0458994Closed
02/08/2023 14:5211/08/2023task0460745Closed
02/08/2023 15:0422/08/2023task0460749Closed
02/08/2023 17:5518/08/2023task0460845Closed
03/08/2023 14:5423/08/2023task0461169Closed
04/08/2023 17:2718/08/2023task0461606Closed
11/10/2023 10:1331/10/2023task0484206Closed
27/03/2023 17:5306/04/2023task0411613Closed
22/05/2023 15:1822/05/2023task0436713Closed
25/05/2023 19:4329/05/2023task0438089Closed
07/07/2023 10:5007/07/2023task0451762Closed
11/10/2023 13:5511/10/2023task0484279Closed
20/03/2023 11:5727/03/2023task0409434Closed
22/03/2023 13:3425/04/2023task0410173Closed
14/04/2023 14:3729/05/2023task0417340Closed
26/04/2023 19:1902/05/2023task0426694Closed
03/05/2023 18:2613/07/2023task0428792Closed
07/05/2023 12:5512/07/2023task0429749Closed
08/05/2023 10:1913/06/2023task0429955Closed
08/05/2023 17:0212/05/2023task0430099Closed
25/05/2023 19:3129/05/2023task0438085Closed
01/06/2023 15:2319/06/2023task0440726Closed
12/06/2023 18:3313/06/2023task0444183Closed
13/06/2023 14:2711/07/2023task0444432Closed
19/06/2023 16:3807/07/2023task0446195Closed
06/07/2023 10:2907/07/2023task0451343Closed
14/07/2023 14:1917/07/2023task0454400Closed
14/07/2023 18:5328/09/2023task0454532Closed
21/07/2023 11:2015/08/2023task0456897Closed
27/07/2023 08:4821/08/2023task0458666Closed
27/07/2023 10:1424/08/2023task0458681Closed
31/07/2023 10:5623/08/2023task0459733Closed
01/08/2023 12:0911/09/2023task0460247Closed
01/08/2023 15:1918/08/2023task0460314Closed
09/08/2023 09:2011/08/2023task0463061Closed



Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.