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.
I have a table which contains a foreign key column named ResourceId and a date column named Assigned. What I'm wanting to do is get the average length of time between dates for all ResourceIds.
I understand how to do this from a programming point of view:
What I don't understand is how to implement this in Power BI or if it is even possible.
Solved! Go to Solution.
Hi @dday9 ,
You may change your measure Average Number of Days like DAX below.
Average Number of Days = VAR earliestDate =MIN ( Table1[Assigned] ) VAR latestDate =MAX ( Table1[Assigned] ) VAR d =DATEDIFF ( earliestDate, latestDate, DAY ) / ( COUNT ( Table1[Assigned] ) - 1 ) VAR _table =SUMMARIZE ( Table1, Table1[FirstName], "_Value", d ) RETURN IF ( HASONEVALUE ( Table1[FirstName]), d, SUMX ( _table, [_Value] ) )
Best Regards,
Amy
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @dday9 ,
You may create column and measure like DAX below.
Column: Group rank= RANKX(FILTER(Table1,Table1[ResourceId]=EARLIER(Table1[ResourceId])),Table1[Assigned],,ASC ,Dense) Measure: = VAR Pdate= CALCULATE(MAX(Table1[Assigned]),FILTER(Table1,Table1[ResourceId]=MAX(Table1[ResourceId])&&Table1[Group rank]=MAX(Table1[Group rank])-1)) VAR DateDiff= DATEDIFF(Pdate, MAX(Table1[Assigned]), DAY) RETURN AVERAGEX(Table1, DateDiff)
If I misunderstood it, could you please share your sample data and desired output screenshots for further analysis? You can also upload sample pbix to OneDrive and post the link here. Do mask sensitive data before uploading.
Best Regards,
Amy
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
So ultimately what I wound up doing was creating the following measure:
Measure = VAR earliestDate = MIN(Table1[Assigned]) VAR latestDate = MAX(Table1[Assigned]) RETURN DATEDIFF(earliestDate, latestDate, DAY) / (COUNT(Table1[Assigned]) - 1)
I then applied the following filters to my grid:
This works so far as it displays the average number of days between rows and it is represented as a decimal rounded to the hundredth place, but what isn't working is the total displayed in the footer of my grid. I'm not sure if this is a bug or what:
Edit - I forgot to mention that when I sort on the last column in ascending order, there are no negative numbers that would cause the total to be 0.00.
Hi @dday9 ,
You may change your measure Average Number of Days like DAX below.
Average Number of Days = VAR earliestDate =MIN ( Table1[Assigned] ) VAR latestDate =MAX ( Table1[Assigned] ) VAR d =DATEDIFF ( earliestDate, latestDate, DAY ) / ( COUNT ( Table1[Assigned] ) - 1 ) VAR _table =SUMMARIZE ( Table1, Table1[FirstName], "_Value", d ) RETURN IF ( HASONEVALUE ( Table1[FirstName]), d, SUMX ( _table, [_Value] ) )
Best Regards,
Amy
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
105 | |
96 | |
79 | |
67 | |
62 |
User | Count |
---|---|
137 | |
106 | |
104 | |
81 | |
63 |