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

dax formula help

I have the following data with the columns id, date en employee

an employee makes an id with a date

with dax formula max en min I calculate the days between the oldest en youngest date by id

Can you help me to calculate the average days by employee

 

youngest date = max(date)

oldest dat = min(date)

days = (youngest date - oldest date)*1

I need to calculate the average days by employee

 

iddateemployee
110-01-17a
211-01-17a
112-01-17a
312-01-17b
213-01-17a
413-01-17b
314-01-17b
514-01-17c
415-01-17b
615-01-17d
516-01-17c
716-01-17e
617-01-17d
817-01-17a
718-01-17e
918-01-17a
819-01-17a
1019-01-17b
920-01-17a
1120-01-17b
1021-01-17b
1221-01-17c
1122-01-17b
1322-01-17d
1223-01-17c
1423-01-17e
1324-01-17d
1425-01-17e
115-02-17a
216-02-17a
317-02-17b
418-02-17b
519-02-17c
620-02-17d
721-02-17e
822-02-17a
923-02-17a
1024-02-17b
1125-02-17b

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

 

Try this

 

=(MAX(Data1[date])-MIN(Data1[date]))/COUNTA(Data1[employee])

Hope this helps.


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

View solution in original post

11 REPLIES 11
skidambi2
Frequent Visitor

I have SQL Data where in i need to filter two feilds from the table and i used this query but i get error .

 

Total Tickets Received = CALCULATE(COUNT('Tickets Submitted'[incidentNumber]),FILTER('Tickets Submitted',('Tickets Submitted'[OwnerSupportOrg]="Global Service Desk",('Tickets Submitted'[status]<>"Cancelled"))))

 

Operator or expression '( )' is not supported in this context.

Anonymous
Not applicable

@skidambi2the expression you have supplied is a DAX statement, but your post indicates that you are trying to make a change to a Query?  Are you trying to use this DAX statement as part of the Power Query code in the Edit Queries section?

If you were hoping to use DAX and create a measure, i'd write it like this:

Total Tickets Received = CALCULATE(
	COUNTROWS('Tickets Submitted'),
	ALL('Tickets Submitted'),
	'Tickets Submitted'[OwnerSupportOrg] = "Global Service Desk",
	NOT 'Tickets Submitted'[status] - "Cancelled"
)

I've had to make assumptions on where you will want to use the measure and have assumed you need the ALL statement to ignore context.  You can remove the ALL row should you handle the filter context within the report page.

error2.png

Thank you for the feedback

Actually i have sql data which is loaded in powerbi

i want to take the count of tickets by filtering two feilds

1) Owner Support Group - ServiceDesk

2) Status is equal to Cancelled

 

When i try to run your query i get this error

 

thank you so much but there are two problems

1) i tried to filter it based on certain feild the value does not change

2) Secondly i have removed another feild from the filter and tried but i get an error can you please have a look

 

Total Tickets Received = CALCULATE(COUNT('Tickets Submitted'[incidentNumber]),FILTER('Tickets Submitted',AND('Tickets Submitted'[OwnerSupportOrg]="Global Service Desk")))


Getting Error "Too few arguments were passed to the AND function. The minimum argument count for the function is 2."

Anonymous
Not applicable

As mentioned when i provided the solution, i have used the ALL statement which will ignore filter context, so that is why when you selected a specific value you noticed no difference.  In some cases removing the ALL statement will do the trick, but this could present you with additional problems depending on the context on how you have used the measure in your visuals.  Its likely you will need to use ALLEXCEPT instead.

 

 

From your last post, here is the statement you appear to be attempting to write

Total Tickets Received = 
CALCULATE(
	COUNTROWS('Tickets Submitted'),
	'Tickets Submitted'[OwnerSupportOrg] = "Global Service Desk"
)

or potentially this if you wanted to know a distinct count of the IDs

Total Tickets Received = 
CALCULATE(
	DISTINCTCOUNT('Tickets Submitted'[incidentNumber]),
	'Tickets Submitted'[OwnerSupportOrg] = "Global Service Desk"
)

Perfect worked fine

Anonymous
Not applicable

I've made a typo in my formula when i was writing it out.  I put a minus sign instead of an equals sign.  Try this instead:

 

Total Tickets Received = CALCULATE(
	COUNTROWS('Tickets Submitted'),
	ALL('Tickets Submitted'),
	'Tickets Submitted'[OwnerSupportOrg] = "Global Service Desk",
	NOT 'Tickets Submitted'[status] = "Cancelled"
)
reije021
Frequent Visitor

additonal info

I need the average days a employee adds an ID

every id has value days and the id's made by the employee should give me the average days by employee calculated from the ID's the employee has made

Hi,

 

Try this

 

=(MAX(Data1[date])-MIN(Data1[date]))/DISTINCTCOUNT(Data1[id])

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

Hi,

 

Try this

 

=(MAX(Data1[date])-MIN(Data1[date]))/COUNTA(Data1[employee])

Hope this helps.


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

Try this measure:

Days = 
VAR startDate = FIRSTDATE('YourTable'[Date])
VAR endDate = LASTDATE('YourTable'[Date])
RETURN
floor(endDate - startDate, 1)

Put this into a matrix with your employee as the rows and this as your values.

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.