Forum Discussion
Assigning values in a new column based on dates
Hi, I need a new column that assigns an entry per property based on dates.
In this scenario, I have 2 properties that need gas checks conducted every year per each property. When we reach the expiry date for a property, a new gas check is performed, and a certification is issued for another year. I need a new column to determine if the checks are being completed on time. The calculation for the new status column is based on the expiry date and the issue date of the next check (per property). Using the table below, I need the column status to be:
- If the issued date of the new check (per property) is the same as the previous expiry date = Completed On Target
- If the issue date is before the previous expiry date = Completed On Target
- If the issue date is later than the previous expiry date = Completed Outside of Target
- If the expiry date of the most recent Gas_ID is before the date today and there is no new Gas_ID, check for that property = Not Completed
- The expiry date of the most recent check is in the future = Current
The first entry per property is blank as they have no previous expiry dates.
| Property | Stat_ID | Issue_Date | Expiry_Date | Status (this is the column I need) |
| 1 Lakeshore Drive | G1 | 01/04/2022 | 01/04/2023 | |
| 1 Lakeshore Drive | G2 | 01/04/2023 | 01/04/2024 | Completed On Target |
| 1 Lakeshore Drive | G3 | 07/06/2024 | 07/06/2025 | Completed Not On Target |
| 1 Lakeshore Drive | G4 | 07/06/2025 | 07/06/2026 | Current |
| 22 Giddings St | G5 | 26/07/2022 | 26/07/2023 | |
| 22 Giddings St | G6 | 29/07/2023 | 29/07/2024 | Completed Not On Target |
| 22 Giddings St | G7 | 06/08/2024 | 06/08/2025 | Completed Not On Target |
| 22 Giddings St | G8 | 01/09/2025 | 01/09/2026 | Current |
Thanks in advance!
Thankyou, mh2587, for your response.
Hi RichOB,We appreciate your enquiry submitted via the Microsoft Fabric Community Forum.
Based on my understanding of the situation, please find attached a screenshot and a sample .pbix file that may help resolve the issue:
We hope the information provided is useful. Should you have any further queries, please feel free to contact the Microsoft Fabric Community.Thank you.
6 Replies
- mh2587
Super User
Status = // Try this might help you and change the "Test" with your table name VAR CurrentProperty = Test[Property] VAR CurrentIssueDate = Test[Issue_Date] VAR CurrentExpiryDate = Test[Expiry_Date] VAR CurrentStatID = Test[Stat_ID] -- get the previous expiry date for the same property VAR PrevExpiryDate = MAXX ( FILTER ( Test, Test[Property] = CurrentProperty && Test[Issue_Date] < CurrentIssueDate ), Test[Expiry_Date] ) -- today’s date VAR Today = TODAY() RETURN IF ( ISBLANK ( PrevExpiryDate ), BLANK(), -- first record per property is blank SWITCH ( TRUE(), -- If the expiry of the most recent record is in the future CurrentExpiryDate > Today && CurrentStatID = MAXX ( FILTER ( Test, Test[Property] = CurrentProperty ), Test[Stat_ID] ), "Current", -- If expiry is before today and it’s the last record for property CurrentExpiryDate < Today && CurrentStatID = MAXX ( FILTER ( Test, Test[Property] = CurrentProperty ), Test[Stat_ID] ), "Not Completed", -- Issued = prev expiry CurrentIssueDate = PrevExpiryDate, "Completed On Target", -- Issued before prev expiry CurrentIssueDate < PrevExpiryDate, "Completed On Target", -- Issued after prev expiry CurrentIssueDate > PrevExpiryDate, "Completed Not On Target" ) ) - RichOB
Post Partisan
Hi mh2587 thank so much for such a detailed reply.
The more I think of this, it needs to be split into 2 measures.
1st measure - for the Completed On Target, Completed Outside Target, Not Completed
2nd measure -for Current, Not Current
If a property has a status of Current, it won't show if it was Completed In Target or Outside of target, so we'd be missing that data for the most recent check for every property. I'll accept this as a solution and re-post another one with that info. Thanks again.
- v-pnaroju-msft
Community Support
Thankyou, mh2587, for your response.
Hi RichOB,We appreciate your enquiry submitted via the Microsoft Fabric Community Forum.
Based on my understanding of the situation, please find attached a screenshot and a sample .pbix file that may help resolve the issue:
We hope the information provided is useful. Should you have any further queries, please feel free to contact the Microsoft Fabric Community.Thank you.
- v-pnaroju-msft
Community Support
Hi RichOB,
We would like to follow up and see whether the details we shared have resolved your problem. If you need any more assistance, please feel free to connect with the Microsoft Fabric community.
Thank you. - v-pnaroju-msft
Community Support
Hi RichOB,
We are following up to see if what we shared solved your issue. If you need more support, please reach out to the Microsoft Fabric community.
Thank you. - v-pnaroju-msft
Community Support
Hi RichOB,
We wanted to see if the information we gave helped fix your problem. If you need more help, please feel free to contact the Microsoft Fabric community.
Thank you.