Forum Discussion
Help me with this SCD type 2 issue. I am a beginner.
- 7 months ago
Hi Rahul_Nair,
Instead of Using calculatetable or allselected, you can use SelectedValue function.
Attached is the working power BI solution for you.
๐ I hope this solution helps you unlock your Power BI potential! If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.
๐ก Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.
๐ As a proud SuperUser and Microsoft Partner, weโre here to empower your data journey and the Power BI Community at large.
๐ Curious to explore more? [Discover here].
Letโs keep building smarter solutions together! - 7 months ago
Hi Rahul_Nair ,
Handling Slowly Changing Dimensions (SCD Type 2) can be tricky at first, but your data model setup with the Surrogate Key (SK) is actually perfect!As @grazitti_sapna mentioned, the issue with your DAX is that using ALLSELECTED and CALCULATETABLE overcomplicates the row context. When you put a measure into a table visual that already has DIM_Records columns, you just need to check the current row's validity against the calendar selection using SELECTEDVALUE.
Here is the exact DAX measure you need to solve this.
The Solution: The DAX Filter Measure
Create this measure and add it to your Table Visual's "Filters on this visual" pane, then set the condition to "is 1".
Is Valid Record = VAR SelectedDate = MAX('DIM_Calendar'[Date]) VAR CurrentValidFrom = SELECTEDVALUE('DIM_Records'[ValidFrom]) VAR CurrentValidTo = SELECTEDVALUE('DIM_Records'[ValidTo]) RETURN IF ( CurrentValidFrom <= SelectedDate && CurrentValidTo >= SelectedDate, 1, 0 )Why this works:
-
Your DIM_Calendar is disconnected, which is exactly the correct approach for this specific filtering requirement.
-
When you use the Date slicer (for example, "on or before 31.03.2020"), MAX grabs that exact upper limit date.
-
The measure then looks at every single row in your table visual. If the SelectedDate falls between that row's ValidFrom and ValidTo dates, it returns 1 (showing the row).
-
This perfectly handles your ID001 example, showing only the active row for the date you slice.
Just make sure your table visual includes the SK or DimensionID so SELECTEDVALUE has a single row to evaluate!
If this solves your filtering issue, please consider giving a Kudo and marking it as the Accepted Solution! โ
This response was assisted by AI for translation and formatting purposes.
-
Hey grazitti_sapna @thanks for the idea. I was not able to open the file you shared. But the idea of using Selectedvalue helped me to find the solution ๐
Rahul_Nair , If it helped, Kindly mark as solution