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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Myst
Frequent Visitor

Group By with min date but keep other columns

So below is the dataset I'm working with. 

 

WRStatusDateWO
1CREA20200103 
1APPR20200225101
2CREA20200223 
2APPR20200225101
3CREA20200420 
4CREA20200423 
4APPR20200424103
5CREA20200606 
6ORIG20200607 

 

Need to sort by WO and find the date difference between the 2 different status and WR it refers to. If one WO refers to two different WRs, find the difference between the older WR and WO. Below is how the sorted table would look like this. Note how WO 101 has two different WRs and days were calculated using WR 1. 

 

WRWODays
110153
41031

 

Would this be possible through DAX or Power Query Editor? 

1 ACCEPTED SOLUTION
v-angzheng-msft
Community Support
Community Support

Hi, @Myst 

 

Try this:

_WO column = 
MAXX(FILTER(ALL('Table'),[WR]=EARLIER('Table'[WR])),[WO])
_OlderDate_APPPR = 
IF(MAX('Table'[WO])<>BLANK()&&MAX('Table'[WR])=MINX(FILTER(ALL('Table'),'Table'[WO]=MAX('Table'[WO])),[WR]),
MINX(FILTER(ALL('Table'),'Table'[WO]=MAX('Table'[WO])&&'Table'[Status]="APPR"),[Date]))
_CREA = 
var _WO=MAXX(FILTER(ALL('Table'),'Table'[WR]=MAX('Table'[WR])),[WO])
var _WR=SUMMARIZE(FILTER(ALL('Table'),'Table'[WO]=_WO),[WR])
RETURN
IF(MAX('Table'[WO])<>BLANK()&&MAX('Table'[WR])=MINX(FILTER(ALL('Table'),'Table'[WO]=MAX('Table'[WO])),[WR]),
MINX(FILTER(ALL('Table'),'Table'[WR] in _WR&&'Table'[Status]="CREA"),[Date]))
_Days = DATEDIFF([_CREA],[_OlderDate_APPPR],DAY)

 

Result:

vangzhengmsft_0-1646906350393.png

Please refer to the attachment below for details.

Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-angzheng-msft
Community Support
Community Support

Hi, @Myst 

 

Try this:

_WO column = 
MAXX(FILTER(ALL('Table'),[WR]=EARLIER('Table'[WR])),[WO])
_OlderDate_APPPR = 
IF(MAX('Table'[WO])<>BLANK()&&MAX('Table'[WR])=MINX(FILTER(ALL('Table'),'Table'[WO]=MAX('Table'[WO])),[WR]),
MINX(FILTER(ALL('Table'),'Table'[WO]=MAX('Table'[WO])&&'Table'[Status]="APPR"),[Date]))
_CREA = 
var _WO=MAXX(FILTER(ALL('Table'),'Table'[WR]=MAX('Table'[WR])),[WO])
var _WR=SUMMARIZE(FILTER(ALL('Table'),'Table'[WO]=_WO),[WR])
RETURN
IF(MAX('Table'[WO])<>BLANK()&&MAX('Table'[WR])=MINX(FILTER(ALL('Table'),'Table'[WO]=MAX('Table'[WO])),[WR]),
MINX(FILTER(ALL('Table'),'Table'[WR] in _WR&&'Table'[Status]="CREA"),[Date]))
_Days = DATEDIFF([_CREA],[_OlderDate_APPPR],DAY)

 

Result:

vangzhengmsft_0-1646906350393.png

Please refer to the attachment below for details.

Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Myst
Frequent Visitor

Would it be possible to get the WO number in all columns based on WR? So something like this:

 

WRStatusDateWO
1CREA20200103101
1APPR20200225101
2CREA20200223101
2APPR20200225101
3CREA20200420 
4CREA20200423103
4APPR20200424103
5CREA20200606 
6CREA20200607 

 

Anonymous
Not applicable

is this what you are looking for?

MattAllington
Community Champion
Community Champion

This video I created should help you https://youtu.be/xN2IRXQ2CvI



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

So it's somewhat similar but I don't know how to approch the open and close dates being on the same column. I need to remove the new CREA date and row if its APPR WO is a duplicate of an old WR. 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors