Forum Discussion
SCD Type 4 - Data Modelling
- 1 year ago
Hi santhidhanuskod ,
To model SCD Type 4 in Power BI without running into many-to-many relationship issues, the best approach is to combine the Live and History tables into a single table. In Power Query, you can standardize the Live table by replacing null values in the ActiveEndDate column with a placeholder like 9999-12-31, which will act as the open-ended period for currently active records. Then, you can merge the Live and History tables using the Table.Combine function in Power Query:
let LiveWithEnd = Table.ReplaceValue(Live, null, #date(9999,12,31), Replacer.ReplaceValue, {"ActiveEndDate"}), Combined = Table.Combine({LiveWithEnd, History}) in CombinedOnce you have the unified Combined table, create a separate Date table using DAX. This Date table should span from the minimum ActiveStartDate to the maximum ActiveEndDate in your data:
DateTable = CALENDAR(MIN(Combined[ActiveStartDate]), MAX(Combined[ActiveEndDate]))Do not create a relationship between the DateTable and the Combined table. Instead, use a slicer on the DateTable[Date] column. To filter records that were active on the selected date, create a measure that checks whether the selected date falls between each row’s ActiveStartDate and ActiveEndDate. This logic should be written in a measure like the following:
ShowActiveRecords := CALCULATE( [SomeMeasure], FILTER( Combined, SELECTEDVALUE(DateTable[Date]) >= Combined[ActiveStartDate] && SELECTEDVALUE(DateTable[Date]) <= Combined[ActiveEndDate] ) )Replace [SomeMeasure] with an actual metric such as COUNTROWS(Combined) or a specific aggregation. This measure will dynamically filter the Combined table to return only the records that were valid (active) on the selected date, based on the user's slicer input. This method avoids direct relationships that could lead to ambiguous many-to-many joins, while still delivering accurate results based on the time window defined by your SCD Type 4 setup.
Best regards,
Hi santhidhanuskod ,
As per the suggestion/solution from DataNinja777, I tried to come up with the data modeling solution that might give you an idea how to handle the SCD Type 4 data without many-to-many relationships.
SCD Type 4 - Data Modelling.pbix
This is an interesting scenario for me as well and good learning to solve this kind of data modleing topics.
Please let me know if you have further questions.
If this reply helped solve your problem, please consider clicking "Accept as Solution" so others can benefit too. And if you found it useful, a quick "Kudos" is always appreciated, thanks!
Best Regards,
Maruthi
LinkedIn - http://www.linkedin.com/in/maruthi-siva-prasad/
X - Maruthi Siva Prasad - (@MaruthiSP) / X