Forum Discussion

Rahul_Nair's avatar
Rahul_Nair
Regular Visitor
7 months ago
Solved

Help me with this SCD type 2 issue. I am a beginner.

Hi everyone, I am implementing SCD Type 2 in Power BI and stuck on one specific filtering problem. Would really appreciate any help. My data model has three tables. First is a Fact Table with c...
  • grazitti_sapna's avatar
    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!

  • burakkaragoz's avatar
    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.