Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hi to all!
I have this data (the letters in first row and numbers in first column are just for refference):
A | B | C | D | E | F | G | H | I | |
1 | Other Date | Cont Date 1 | Cont Date 2 | Cont Date 3 | Prop Date 1 | Prop Date 2 | Prop Date 3 | Result 1 | Result 2 |
2 | 04/07/2016 | 04/05/2017 | 16/02/2017 | 20/09/2016 | 10/09/2017 | 04/02/2017 | 10/01/2017 | 78 | 0 |
3 | null | null | null | null | 23/11/2016 | 17/10/2016 | 22/01/2017 | null | null |
4 | 11/08/2016 | 05/08/2016 | null | null | 11/01/2017 | null | null | 0 | 159 |
5 | null | 25/05/2016 | 10/08/2016 | 19/12/2016 | 13/02/2017 | 07/11/2017 | 17/01/2017 | null | 29 |
6 | 05/10/2016 | null | 06/07/2017 | null | 23/01/2017 | 03/09/2016 | 16/01/2017 | 274 | 0 |
7 | 07/09/2016 | 04/08/2017 | 15/09/2016 | 20/04/2017 | null | null | null | 8 | null |
8 | 27/12/2015 | 16/07/2017 | null | 04/06/2016 | 26/09/2017 | null | null | 160 | 72 |
I want to calculate the difference between date columns in Power Query, Getting non-negative values.
If you calculate the results in Excel, you make this like (without take care about the null's in the Excel formula):
Result1 = MAX(0;MIN(B2;C2;D2)-A2)
Result2 = MAX(0;MIN(E2;F2;G2)-MAX(B2;C2;D2))
I need the results like I show in red text. The date's columns are non-contiguous (if this information is needed).
Thanks in advanced for your answers. Blessings!
Solved! Go to Solution.
You can basically use the same style when addiing column like this:
For Result1:
List.Max({ #duration(0,0,0,0),
List.Min({[Cont Date 1],[Cont Date 2],[Cont Date 3]}) - [Other Date]
})
And for Result2:
List.Max({ #duration(0,0,0,0),
List.Min({[Prop Date 1],[Prop Date 2],[Prop Date 3]})-List.Max({[Cont Date 1],[Cont Date 2],[Cont Date 3]})
})
You create lists as your "ranges" to choose from and then you can use List.Min or List.Max as the equivalent to MIN or MAX in Excel.
To create a list, you wrap your comma-separated elements into curly brackets: { FirstElement, SecondElement... }
Also you have to format the first 0 as a duration for the formula to work properly.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Not so elegant any more then:
= Table.AddColumn(#"Added Custom", "Custom.1", each try if List.Max({null, List.Min({[Prop Date 1],[Prop Date 2],[Prop Date 3]})-List.Max({[Cont Date 1],[Cont Date 2],[Cont Date 3]}) }) > #duration(0,0,0,0) then List.Max({null, List.Min({[Prop Date 1],[Prop Date 2],[Prop Date 3]})-List.Max({[Cont Date 1],[Cont Date 2],[Cont Date 3]}) }) else 0 otherwise null)
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
You can basically use the same style when addiing column like this:
For Result1:
List.Max({ #duration(0,0,0,0),
List.Min({[Cont Date 1],[Cont Date 2],[Cont Date 3]}) - [Other Date]
})
And for Result2:
List.Max({ #duration(0,0,0,0),
List.Min({[Prop Date 1],[Prop Date 2],[Prop Date 3]})-List.Max({[Cont Date 1],[Cont Date 2],[Cont Date 3]})
})
You create lists as your "ranges" to choose from and then you can use List.Min or List.Max as the equivalent to MIN or MAX in Excel.
To create a list, you wrap your comma-separated elements into curly brackets: { FirstElement, SecondElement... }
Also you have to format the first 0 as a duration for the formula to work properly.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Great ImkeF!
Thanks for your answer. But... If I want to get null results like the example in red, how do you get it? Blessings!
Not so elegant any more then:
= Table.AddColumn(#"Added Custom", "Custom.1", each try if List.Max({null, List.Min({[Prop Date 1],[Prop Date 2],[Prop Date 3]})-List.Max({[Cont Date 1],[Cont Date 2],[Cont Date 3]}) }) > #duration(0,0,0,0) then List.Max({null, List.Min({[Prop Date 1],[Prop Date 2],[Prop Date 3]})-List.Max({[Cont Date 1],[Cont Date 2],[Cont Date 3]}) }) else 0 otherwise null)
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
User | Count |
---|---|
128 | |
108 | |
100 | |
64 | |
62 |
User | Count |
---|---|
136 | |
113 | |
102 | |
71 | |
60 |