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
ccindyp
Frequent Visitor

Average of averages between 2 dates based on calculated column

Hello,

 

I have been working on this for a few weeks and I don’t understand why it’s not retrieving the correct calculation. I am hoping that you could help guiding me in the right direction.

 

I have a fact table as  sample below:

CustomerCustomer TextTicketTicket TextPriorityCategory IDColumn 1SupportReported OnReported ByIn ProcessResolved OnClosingStatusChanged OnChanged ByReported to resolved
1234567Client 112345Ticket descriptionNormalCat 1_IDCat 1John Doe03-Jan-24Client 103-Jan-2404-Jan-2408-Jan-24Closed08-Jan-24John Doe1
1234567Client 112346Ticket descriptionNormalCat 2_IDCat 2Jane Doe15-Mar-23Client 116-Mar-2322-Mar-2324-Mar-23Closed24-Mar-23Jane Doe7
1234567Client 112347Ticket descriptionUrgentCat 3_IDCat 3John Doe05-Jan-24Client 108-Jan-2409-Jan-2415-Jan-24Closed15-Jan-24John Doe4
1234567Client 112348Ticket descriptionUrgentCat 1_IDCat 1Jane Doe05-Jun-23Client 105-Jun-2308-Jun-2303-Jul-23Closed03-Jul-23Jane Doe3
1234567Client 112349Ticket descriptionNormalCat 2_IDCat 2John Doe18-Jan-24Client 118-Jan-24  In Process24-Jan-24John Doe0
1234568Client 212345Ticket descriptionUrgentCat 3_IDCat 3Jane Doe03-Jul-23Client 203-Jul-2304-Jul-2318-Aug-23Closed18-Aug-23Jane Doe1
1234568Client 212345Ticket descriptionNormalCat 1_IDCat 1John Doe24-Jan-24Client 224-Jan-24  In Process25-Jan-24John Doe0
1234568Client 212345Ticket descriptionNormalCat 2_IDCat 2Jane Doe24-Jan-24Client 224-Jan-24  Customer29-Jan-24Jane Doe0

 

 

From this table I need to know the average time between a “reported” ticket to a “resolved” ticket overall and by customer and by category last year (independently from status).

 

I started with adding a calculated column. Both in DAX and power query are retrieving the same result (whole or decimal number):

Attempt 1:

Reported to resolved =

DATEDIFF('Fact - All tickets'[Reported On], 'Fact - All tickets'[Resolved On], DAY))

 

Attempt 2:

Reported to resolved =

IF(ISBLANK('Fact - All tickets'[Resolved On]),0,DATEDIFF('Fact - All tickets'[Reported On], 'Fact - All tickets'[Resolved On], DAY))

 

When I put this formula to be evaluated in DAX studio, it gives me back an error: “the expression specified in the query is not a valid table expression”.

I thought I could reuse some previous post to get my answer, but I cannot apply the results (still gives me incorrect result):

https://community.fabric.microsoft.com/t5/Power-Query/Average-of-Datediff/m-p/2198025#M65025

https://community.fabric.microsoft.com/t5/Desktop/Average-of-Datediff-with-a-condition/m-p/3556960#M...

https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Total-average-of-datediff/m-p/344728...

https://community.fabric.microsoft.com/t5/Desktop/Average-and-Median-DAX-calculating-incorectly/m-p/...

 

 

Then based on that I tried different formulas:

10 - Average reported to resolved 2023 =

AVERAGE(

    'Fact - All tickets'[Reported to resolved]

 

10 - AverageX reported to resolved 2023 =

AVERAGEX(

    SUMMARIZE(

    'Fact - All tickets',

    'Dim - Customer'[Customer Text],

    "Average days to resolve", AVERAGE('Fact - All tickets'[Reported to resolved])),

    [Average days to resolve]

)

 

Other option with same incorrect result:

10 - AverageX reported to resolved 2023 - values =

AVERAGEX(

    VALUES('Dim - Customer'[Customer Text]),

      CALCULATE([10 - Average reported to resolved 2023]))

 

I also tried another option with Calculate:

 

Test 5 = CALCULATE(AVERAGE('Fact - All tickets'[Reported to resolved]),ALL('Fact - All tickets'[Customer Text]))

 

I tried to test parts of the formulas in DAX Studio and both summarize and Values functions are retrieving correct data :

 

SUMMARIZE(

    'Fact - All tickets',

    'Dim - Customer'[Customer Text]

 

VALUES('Dim - Customer'[Customer Text])

 

 

I then divided my table only to get results for client 1 based on the following sample:

Customer

A

B

Client 1

1.22

1

Client 1

6.87

7

Client 1

3.17

3

 

 

Test average =

AVERAGE(

    'Table'[B]

)

 

The A column is the row result as I normally get the data in Date/time format from excel and then I remove the time which gives me rounding number which I can explain. The difference is not the result I get from my formulas though.

From this I do get the correct result: 3.65, whereas previous incorrect measures (tests) are giving the same result of 3.20.

 

Format of the column is whole or decimal number (both in power query editor and in the table view).

 

Relationship between fact table and customer dimension table is based on customer ID, many to 1 (single or both directions, I tried both) and customer ID is a text format in both table because I do receive some tickets with no customer ID (“#”) that I need to register as well.

 

Relationship between fact table and date table is based on inactive relationships (many to one, single) on all the dates and I use the “userelationship” function when needed in DAX, but no need here because I have a filter on the page with the date.

 

So I think something is wrong with my calculated column, but I am not sure how to dig into this problem and I do not understand where it could come from. Are you able to help please?

 

If you need more info on the data model, please let me know.

 

Thank you very much,

 

Cindy

1 ACCEPTED SOLUTION

Hello, 

 

Seems to be working with the summarize function.

 

Thank you

View solution in original post

3 REPLIES 3
ccindyp
Frequent Visitor

Hello, 

Thank you for your reply. 

I evaluate the first formula through DAX studio and get the same error : 

"the expression specified in the query is not a valida table expression". Why do I get this error?

 

In addition, I am not sure the coalesce function will help in what I want to achieve, as I am replacing blank values by today, which is not correct. Blank values should not be counted in that case because the ticket is not solved, therefore we cannot apply the "reported to resolve" average date.

 

I tried the formula never the less and I get 34.28, indepently from filter on the pages which should be filtering only on year 2023. when I swith to 2024 the result is not updating. 

 

I should be getting a result closed to 22.xx days overall. 

 

Do you think my column is not working because I have tickets that are unresolved (blank values)?

 

I am not sure how to tacle this issue. 

 

Thank you

Hello, 

 

Seems to be working with the summarize function.

 

Thank you

amitchandak
Super User
Super User

@ccindyp , Based on what I got try measures like

 

 

At ticket level
Avg Day=
Averagex('Fact - All tickets', DATEDIFF('Fact - All tickets'[Reported On], coalesce('Fact - All tickets'[Resolved On], today()), DAY))

For customer level first sum and then avg
Total time =
Sumx('Fact - All tickets', DATEDIFF('Fact - All tickets'[Reported On], coalesce('Fact - All tickets'[Resolved On], today()), DAY))


Avg time for customer = Averagex(values('Fact - All tickets'[Csutomer]), [Total time])

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.