Forum Discussion
Power Query If and then statement
I have a database and need some help with Mean time between failure. I would like to take the DAX I have and convert it over to use in Power Query instead of DAX.
Mean Time Between Failure (MTBF) and Power BI - Microsoft Power BI Community
This is where I got my inspriration for the formula that I use currently. I works great but I need to have this done in Power Query so I can manipulate the data in Power Bi for Ranking and divding data up into Top and Bottom tens per each site I have. Below is the DAX statement I use.
| BarCode | Date_Ent | Date_Warranty | MTBF |
| A-147853 | 11/12/2021 | 3/30/2022 | |
| A-236056 | 9/21/2021 | 1/6/2022 | |
| A-236545 | 5/1/2020 | 9/14/2020 | |
| A-236545 | 9/15/2020 | 6/2/2021 | |
| A-236561 | 1/31/2019 | 4/24/2019 | |
| A-236561 | 10/17/2019 | 12/20/2019 | |
| A-236561 | 1/27/2020 | 3/16/2020 | |
| A-236585 | 6/16/2020 | 1/14/2021 | |
| A-236585 | 1/15/2021 | 2/23/2021 | |
| A-236585 | 2/24/2021 | ||
| A-236601 | 12/28/2018 | 8/19/2019 | |
| A-236613 | 12/19/2018 | 11/3/2020 | |
| A-236613 | 11/6/2020 | 12/1/2020 | |
| A-236613 | 12/2/2020 | ||
| A-236639 | 7/3/2018 | 4/5/2019 | |
| A-236639 | 5/24/2019 | 7/24/2019 | |
| A-236639 | 7/24/2019 | 10/9/2020 | |
| A-236639 | 10/20/2020 | ||
| A-236644 | 2/14/2020 | 4/24/2020 | |
| A-236644 | 8/11/2020 | 10/19/2020 | |
| A-236661 | 1/21/2020 | 9/5/2020 | |
| A-236661 | 9/9/2020 | 11/19/2020 | |
| A-236662 | 2/7/2011 | ||
| A-236668 | 8/24/2018 | 4/12/2019 | |
| A-236668 | 4/12/2019 | 5/18/2020 | |
| A-236668 | 5/21/2020 | ||
| A-236689 | 6/20/2019 | 9/12/2019 | |
| A-236689 | 9/12/2019 | 2/17/2020 | |
| A-236689 | 8/19/2020 | 11/17/2020 | |
| A-236689 | 11/17/2020 | 2/23/2021 | |
| A-236742 | 8/8/2019 | 7/22/2020 | |
| A-608848 | 12/5/2018 | 2/15/2020 | |
| A-608849 | 4/24/2019 | 9/29/2020 | |
| A-608849 | 9/29/2020 | 5/4/2021 | |
| A-608860 | 3/25/2019 | 5/30/2019 | |
| A-608860 | 6/10/2019 | 9/4/2019 | |
| A-608862 | 11/20/2019 | 6/5/2020 | |
| A-608862 | 11/10/2020 | 3/3/2022 | |
| A-608876 | 4/29/2020 | 6/9/2020 | |
| A-608878 | 7/11/2019 | ||
| A-608878 | 8/20/2019 | 9/3/2019 | |
| A-608878 | 12/10/2019 | 12/16/2019 | |
| A-608878 | 7/8/2020 | 7/31/2020 | |
| A-608878 | 8/5/2020 | ||
| A-608878 | 8/13/2021 | 11/11/2021 | |
| A-608878 | 3/22/2022 | ||
| A-608888 | 8/5/2019 | 11/25/2019 | |
| A-608888 | 1/8/2020 | ||
| A-608898 | 6/3/2021 | 7/26/2021 | |
| A-608898 | 12/6/2021 | 3/21/2022 | |
| A-608900 | 7/8/2020 | 7/22/2020 | |
| A-767706 | 10/14/2020 | 11/18/2020 | |
| A-767706 | 12/8/2020 | 1/5/2021 | |
| A-767707 | 7/28/2020 | 8/27/2021 | |
| A-767708 | 7/28/2020 | 2/1/2021 | |
| A-767709 | 7/30/2020 | ||
| A-767710 | 7/30/2020 | 8/25/2020 |
Hi Anonymous
First add a custom column to get the Next Date_Ent on every row.
List.Min(Table.Column(Table.SelectRows(#"previous step name",(x)=> x[BarCode]=[BarCode] and x[Date_Ent]>[Date_Ent]),"Date_Ent"))Then compare [Next] with [Date_Warranty] to get total duration hours.
if [Next] = null then Duration.TotalHours(DateTime.LocalNow()-([Date_Warranty] & #time(0,0,0))) else Duration.TotalHours([Next]-[Date_Warranty])Last, change MTBF column to whole number type.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
1 Reply
- v-jingzhangCommunity Support
Hi Anonymous
First add a custom column to get the Next Date_Ent on every row.
List.Min(Table.Column(Table.SelectRows(#"previous step name",(x)=> x[BarCode]=[BarCode] and x[Date_Ent]>[Date_Ent]),"Date_Ent"))Then compare [Next] with [Date_Warranty] to get total duration hours.
if [Next] = null then Duration.TotalHours(DateTime.LocalNow()-([Date_Warranty] & #time(0,0,0))) else Duration.TotalHours([Next]-[Date_Warranty])Last, change MTBF column to whole number type.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.