Forum Discussion
Create rental steps by comparing dates across rows
- 6 years ago
Hi Anonymous
In your table,
1. open Edit queries, first sort by [number], second sort by [start date], then add an index column from 1.
2. close&&apply
3. create calculated columns
flag = VAR min_ = CALCULATE ( MIN ( 'Table'[Index] ), ALLEXCEPT ( 'Table', 'Table'[number] ) ) VAR max_ = CALCULATE ( MAX ( 'Table'[Index] ), ALLEXCEPT ( 'Table', 'Table'[number] ) ) RETURN SWITCH ( [Index], min_, "min", max_, "max" ) add start = SWITCH ( TRUE (), [flag] <> "min" && [productname] = "half rent", [end date] + 1, [flag] = "min", [start date] ) add end = CALCULATE ( MIN ( 'Table'[start date] ), FILTER ( ALLEXCEPT ( 'Table', 'Table'[number] ), 'Table'[Index] = EARLIER ( 'Table'[Index] ) + 1 ) ) - 14.create a new table with dax codes below
Table 3 = UNION ( FILTER ( SUMMARIZE ( 'Table', [number], 'Table'[productname], 'Table'[start date], [end date], 'Table'[amount] ), [productname] <> "full rent" ), SELECTCOLUMNS ( 'Table', "number", [number], "productname", "full rent", "start date", [add start], "end date", [add end], "amount", [amount] ) )5.add columns to a table visual, then "export data".
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous
You could try Power KPI.
See a similar thread:
Besides, i am trying to reproduce your problem, is the table below correct as your actual one?
| number | productname | start date | end date |
| 1 | full rent | 8/26/2014 | 8/25/2024 |
| 1 | half rent | 8/26/2020 | 12/25/2020 |
| 1 | half rent | 8/26/2021 | 12/25/2021 |
| 1 | half rent | 8/26/2022 | 12/25/2022 |
| 1 | half rent | 8/26/2023 | 1/25/2024 |
| 2 | full rent | 8/26/2019 | 8/25/2022 |
| 2 | half rent | 8/26/2020 | 12/25/2020 |
| 2 | half rent | 8/26/2021 | 1/25/2022 |
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-juanli-msft Yes that custom visual looks good, however, I just want to get the data into an appropriate format for excel export. Further down the line I may use the stepped line visual.
And yes, the table is correct. Using your table, I would want it to look like the following format (i haven't filled out every step)
| contract number | productname | start date | end date | amount (£) |
| 1 | full rent | 8/26/2014 | 8/25/2020 | 60k |
| 1 | half rent | 8/26/2020 | 12/25/2020 | 30k |
| 1 | full rent | 12/26/2020 | 8/25/2021 | 60k |
| 1 | half rent | 8/26/2021 | 12/25/2021 | 30k |
| 1 | full rent | … | … | … |
| … | … | … | … | |
| 2 | full rent | 8/26/2019 | 8/25/2020 | 70k |
| 2 | half rent | 8/26/2020 | 12/25/2020 | 35k |
| … | … | … | … |
The key assumptions are:
a) Full rent will always be the first step on a contract
b) amount (£) is a field direct from datasource, no need to calc
- v-juanli-msft6 years ago
Community Support
Hi Anonymous
In your table,
1. open Edit queries, first sort by [number], second sort by [start date], then add an index column from 1.
2. close&&apply
3. create calculated columns
flag = VAR min_ = CALCULATE ( MIN ( 'Table'[Index] ), ALLEXCEPT ( 'Table', 'Table'[number] ) ) VAR max_ = CALCULATE ( MAX ( 'Table'[Index] ), ALLEXCEPT ( 'Table', 'Table'[number] ) ) RETURN SWITCH ( [Index], min_, "min", max_, "max" ) add start = SWITCH ( TRUE (), [flag] <> "min" && [productname] = "half rent", [end date] + 1, [flag] = "min", [start date] ) add end = CALCULATE ( MIN ( 'Table'[start date] ), FILTER ( ALLEXCEPT ( 'Table', 'Table'[number] ), 'Table'[Index] = EARLIER ( 'Table'[Index] ) + 1 ) ) - 14.create a new table with dax codes below
Table 3 = UNION ( FILTER ( SUMMARIZE ( 'Table', [number], 'Table'[productname], 'Table'[start date], [end date], 'Table'[amount] ), [productname] <> "full rent" ), SELECTCOLUMNS ( 'Table', "number", [number], "productname", "full rent", "start date", [add start], "end date", [add end], "amount", [amount] ) )5.add columns to a table visual, then "export data".
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.