cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rbangari001
Frequent Visitor

Calculate the no of days for a Epic which was spent in each state

 Hi,

 

I would like to know how to calcuate the days which was spent in each state. Please find the find the sample data below. Please help on how to create a index field in power Query and caculated column in the front end

 

Work Item IdDateState
11436/17/21Build
11436/18/21Build
11436/19/21Build
11436/20/21Build
11436/21/21Build
11436/22/21Build
11436/23/21UAT
11436/24/21UAT
11436/25/21UAT
11436/26/21UAT
11436/27/21UAT
11436/28/21UAT
11436/29/21UAT
11436/30/21Closed
11437/1/21Closed
11437/2/21Closed

 

@Baskar I have see your response to the other thread for the same kind of question. Can you please help on how to create a index for this one in the power Query and create a new calcuated column in the front end.

 

 

 

@phyten Please help

 

 

Power Query for Index =
CALCULATE(DISTINCTCOUNT('Epic - All History Daily'[Date]),
FILTER('Epic - All History Daily',
'Epic - All History Daily'[State]= EARLIER('Epic - All History Daily'[State]) &&
'Epic - All History Daily'[Date] <=EARLIER( 'Epic - All History Daily'[Date])))
 
 
Front end Calculated Column

 

Diff =
VAR vKEY = 'Epic - All History Daily'[Work Item Id]
VAR vINDEX = 'Epic - All History Daily'[Index]

RETURN

DATEDIFF(
CALCULATE( VALUES('Epic - All History Daily'[Date]),
FILTER( ALL('Epic - All History Daily'),
'Epic - All History Daily'[Work Item Id] = vKEY &&
'Epic - All History Daily'[Index] = (vINDEX - 1)
)
),'Epic - All History Daily'[Date],DAY)
 
I have got the error in front end. Attached the screenshot for reference
 
 

2021-09-26_20-28-06.png

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @rbangari001 

 

Your Power Query for Index is a DAX formula for a calculated column like below image, not in Power Query. 

21092901.jpg

 

At present you have the error you highlighted because VALUES function get multiple dates that have the same work item id and index while DATEDIFF expects a single date value there. 

 

If the Index column already returns the correct result, you can try below code for Diff column.

Diff = 
VAR vKEY = 'Epic - All History Daily'[Work Item Id]
VAR vINDEX = 'Epic - All History Daily'[Index]
VAR vState = 'Epic - All History Daily'[State]
RETURN
DATEDIFF(
CALCULATE( VALUES('Epic - All History Daily'[Date]),
FILTER( ALL('Epic - All History Daily'),
'Epic - All History Daily'[Work Item Id] = vKEY &&
'Epic - All History Daily'[Index] = (vINDEX - 1) &&
'Epic - All History Daily'[State] = vState
)
),'Epic - All History Daily'[Date],DAY)

 

If this doesn't give you correct result, can you provide the expected output in Diff column?

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

2 REPLIES 2
v-jingzhang
Community Support
Community Support

Hi @rbangari001 

 

Your Power Query for Index is a DAX formula for a calculated column like below image, not in Power Query. 

21092901.jpg

 

At present you have the error you highlighted because VALUES function get multiple dates that have the same work item id and index while DATEDIFF expects a single date value there. 

 

If the Index column already returns the correct result, you can try below code for Diff column.

Diff = 
VAR vKEY = 'Epic - All History Daily'[Work Item Id]
VAR vINDEX = 'Epic - All History Daily'[Index]
VAR vState = 'Epic - All History Daily'[State]
RETURN
DATEDIFF(
CALCULATE( VALUES('Epic - All History Daily'[Date]),
FILTER( ALL('Epic - All History Daily'),
'Epic - All History Daily'[Work Item Id] = vKEY &&
'Epic - All History Daily'[Index] = (vINDEX - 1) &&
'Epic - All History Daily'[State] = vState
)
),'Epic - All History Daily'[Date],DAY)

 

If this doesn't give you correct result, can you provide the expected output in Diff column?

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

Hello @v-jingzhang Thank you so so much. It worked 😊 Sorry about the confusion, Yes it is a DAX query for Index. I'm new to power BI, so got confused with terminology.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors