Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hello,
have a dataset where I want to filter out (or combine) rows when the difference between the enddate of this row and the startdate of another row is lower than 31 days.
The dataset looks something like this (the last columns show what I would like to accomplish):
ClientID | ProductID | Startdate | Enddate | StartDate(What I want) | Enddate (What I want) |
1 | 231 | 1-1-17 | 28-2-17 | 1-1-17 | 30-6-17 |
1 | 231 | 1-3-17 | 31-5-17 | 1-1-17 | 30-6-17 |
1 | 231 | 1-6-17 | 30-6-17 | 1-1-17 | 30-6-17 |
1 | 231 | 1-9-17 | 30-10-17 | 1-9-17 | 31-12-17 |
1 | 231 | 1-11-17 | 31-12-17 | 1-9-17 | 31-12-17 |
1 | 231 | 1-1-18 | 1-9-17 | 31-12-17 | |
In Excel this is quite easy, but I don't know how to accomplish it in Power BI.
Can someone help me?
Thanks!!
Dear @nielsvanbruggen,
You can create a new column, using this formular:
And all the same ClientID will have same min startDate and max Endate.
Rregards,
ManNVSM.
Thanks for all the reactions!
I did create new columns with the DAX-formulas you presented. The problem is that when the enddate in one row is more than 31 days before the startdate of the next row, I want the formula to keep the startdate of that row and use it for the rows to come (for the combination clientid and product.
Is this clear enough? I hope so! 🙂
Hi!
Yes, I can.
What I do in Excel is that I make additional columns to "group" the existing table. I use the following formulas:
Columns F, G, H and I make a new grouped table (how I want it) with only data in rows 3, 5 and 7.
A | B | C | D | E | F | G | H | I | |
ClientID | Product | Startdate | Enddate | Startdate (new) | Startdate (new 2) | Enddate (new) | Product (new) | ClientID (new) | |
1 | 123 | 001 | 1-1-17 | 31-1-17 | =C1 --> 1-1-17 | =IF(E1=E2;"";E1) --> "" | =IF(E1=E2;"";D1) --> "" | =IF(E1=E2;"";B1) --> "" | =IF(E1=E2;"";A1) --> "" |
2 | 123 | 001 | 1-2-17 | 28-2-17 | =IF(AND( A2=A1;B2=B1;C2<(D1+31)); E1; C1) --> 1-1-17 | =IF(E2=E3;"";E2) --> "" | =IF(E2=E3;"";D2) --> "" | =IF(E2=E3;"";B2) --> "" | =IF(E2=E3;"";A2) --> "" |
3 | 123 | 001 | 1-3-17 | 31-3-17 | =IF(AND( A3=A2;B3=B2;C3<(D2+31)); E2; C2) --> 1-1-17 | =IF(E3=E4;"";E3) --> 1-1-17 | =IF(E3=E4;"";D3) --> 31-3-17 | =IF(E3=E4;"";B3) --> 001 | =IF(E3=E4;"";A3) --> 123 |
4 | 123 | 001 | 1-8-17 | 30-8-17 | =IF(AND( A4=A3;B4=B3;C4<(D3+31)); E3; C3) --> 1-8-17 | =IF(E4=E5;"";E4) --> "" | =IF(E4=E5;"";D4) --> "" | =IF(E4=E5;"";B4) --> "" | =IF(E4=E5;"";A4) --> "" |
5 | 123 | 001 | 1-9-17 | 31-9-17 | =IF(AND( A5=A4;B5=B4;C5<(D4+31)); E4; C4) --> 1-8-17 | =IF(E5=E6;"";E5) --> 1-8-17 | =IF(E5=E6;"";D5) --> 31-9-17 | =IF(E5=E6;"";D5) --> 001 | =IF(E5=E6;"";A5) --> 123 |
6 | 123 | 002 | 1-1-17 | 31-1-17 | =IF(AND( A6=A5;B6=B5;C6<(D5+31)); E6; C6) --> 1-1-17 | =IF(E6=E7;"";E6) --> "" | =IF(E6=E7;"";D6) --> "" | =IF(E6=E7;"";B6) --> "" | =IF(E6=E7;"";A6) --> "" |
7 | 123 | 002 | 15-2-17 | 31-3-17 | =IF(AND( A7=A6;B7=B6;C7<(D6+31)); E7; C7) --> 1-1-17 | =IF(E7=E8;"";E7) --> 1-1-17 | =IF(E7=E8;"";D7) --> 31-3-17 | =IF(E7=E8;"";D7) --> 002 | =IF(E7=E8;"";D7) --> 123 |
8 | 123 | 002 | 1-9-17 | 31-9-17 | =IF(AND( A8=A7;B8=B7;C8<(D7+31)); E8; C8) --> 1-9-17 |
Hopefully you can help me with this one!
Thanks!
Niels
Yes, of course!
To create the start and end dates I want I use this formula in Excel:
- "Startdate new":
Row 1: "=Startdate row 1"
Row 2-.. "=IF(
AND(
ClientID row 2 = ClientID row 1;
Startdate row 2= Startdate row 1;
Startdate row 2 < (Enddate row 1 + 31));
Startdate new row 1 ; Startdate row 2 )
- "Startdate new 2"
"=IF(Startdate new row 1 = Startdate new row 2;
""; Startdate new row 1)
- "Enddate new"
"=IF(Startdate new row 1 = Startdate new row 2;
""; Enddate row 1)
The I perform the steps of "Startdate new 2' and "Enddate new" also for "Product new" and "ClientID new". These steps all together make that I "group" these rows in a new table.
I really want to do this in Power BI, but I don't know how to do this. Maybe in Power Query??
Thanks all!
Niels
Hi @nielsvanbruggen,
"filter out (or combine) rows when the difference between the enddate of this row and the startdate of another row is lower than 31 days."
What does startdate of another row mean? How do determine which startdate is used to compare with enddate in current row?
What is your desired output? Do you want a new table which has been filtered? Or do you want to add a new calculated column in source table?
Please provide more description about [StartDate(What I want)] and [Enddate(what I want)]. I don't understand how to get values like this.
Best regards,
Yuliana Gu
Hey, i didn't get the idea, is possible to detail it?
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
92 | |
86 | |
85 | |
67 | |
49 |
User | Count |
---|---|
140 | |
113 | |
104 | |
64 | |
60 |