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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Insert duplicate row based on comparing dates across rows

 

I have a list of contracts for rental properties.

On each contract is a list of subscription lines detailing how much the customer will be paying across a certain timeframe - indicated by SBQQ__StartDate__c and SBQQ__EndDate__c. In the example below, the customer's contract starts on 26.08.2014 (paying full rent price) but is then offered 'Half Rent' from 26.08.2020 - 25.12.2020

After this period of half rent, the customer is returned back to full rent (SBQQ__ProductName__c = Office) - the problem is that we don't have a unique line/row for this entry. It's salesforce data so there must be some automation on the system which isn't replicated in the underlying dataset.

 

What I need to do is create a timeline of rental steps which I will then be index by contract & flatten into one line so I would have 1 contract number and all the flattened rental/contract steps (with the amount being payed by the customer at each step) pushed out into a very long wide dataset.

 

In my head this would be very easy to achieve, especially if I could utilise cell referencing, the logic is something like:
if datediff(SBQQ__EndDate__c[row 1], SBQQ_StartDate__c[row 2]) > 1 then insert a duplicate row of the full rent line (SBQQ_ProductName__c = Office)

 

In simple english it's basically: "if there is a gap between the end date of the n rental step and start of n+1 rental step then return to full rent during this gap"

Here's the data for one contract and its rental steps. I've also attached a drawn picture to show how the concept is working in theory. I've got the code working to index by contract and flatten using SUMMARIZE() in DAX, I just need to insert a duplicate row each time there is a gap in the 'half rent' steps (or there may be a more elegant solution)

 

 

20200203_155044.jpg

 

Subscription LineNameSBQQ__ContractNumber__cSBQQ__ProductName__cSBQQ__StartDate__cSBQQ__EndDate__cTotal_Annualised_Rent__cTotal_Annual_Billable_Amount__c
SUB-000644200002588Office26/08/201425/08/2024568750
SUB-001704500002588Half Rent26/08/202025/12/2020null28437.49
SUB-001704600002588Half Rent26/08/202125/12/2021null28437.49
SUB-001704700002588Half Rent26/08/202225/12/2022null28437.49
SUB-001704800002588Half Rent26/08/202325/01/2024null28437.496

 

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

Do you wanna get the column which is marked in red as below?(If not,advise me what is your expected output)

Annotation 2020-02-04 135308.png

 

If so ,first go to "edit queries">"Add column">"Index column">"From 1"

Then you need a calculated column as below:

 

 

Column = 
var a=CALCULATE(MAX('Table'[SBQQ__EndDate__c]),'Table'[Index]=EARLIER('Table'[Index]),ALLEXCEPT('Table','Table'[SBQQ__ContractNumber__c]))
VAR b=CALCULATE(MAX('Table'[SBQQ__StartDate__c]),'Table'[Index]=EARLIER('Table'[Index])+1,ALLEXCEPT('Table','Table'[SBQQ__ContractNumber__c]))
Return
SWITCH(TRUE(),'Table'[Index]=1,"Office",DATEDIFF(b,a,DAY)<>1,"half rent",BLANK())

 

Then you will see :

 

Annotation 2020-02-04 140647.png

 

For the related .pbix file,pls click here.

 

Best Regards,
Kelly

Anonymous
Not applicable

@v-kelly-msft thanks for the quick response - unfortunately I already have the product name column in my dataset.

 

My expected output would be something like this

contract numberproductnamestart dateend date
00002588office (full rent)8/26/20148/25/2020
00002588half rent8/26/202012/25/2020
00002588office (full rent)12/26/20208/25/2021
00002588half rent8/26/202112/25/2021
00002588office (full rent)
...

 

So I need some way to compare the end date of the half rent and check if the next step is directly after it (less than 1 day), if it's not (if there is a gap > 1 day), then we need to jump back up to full rent until the next step. This behaviour will continue untill all the rent steps have been actioned, and the final step would be the remainder of the office/full rent line.

 

You can assume the first line, per contract, will be the full rent line. Hope that makes sense, thanks alot for your help

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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