Forum Discussion

JCortez's avatar
JCortez
Frequent Visitor
5 days ago
Solved

Clients in a certain program

  Hello, I am looking to create dax code to pull clients enrolled in Program3 only. They might be enrolled in Program1 or Programs2 at the same time, but I only want to see clients who are in progr...
  • grazitti_sapna's avatar
    grazitti_sapna
    4 days ago

    Hi JCortez​,

    You can use below dax

    Program3_Only =
    VAR CurrentClient = Client_program[ClientID]
    VAR HasProgram3 =
        CALCULATE(
            COUNTROWS(Client_program),
            FILTER(
                ALL(Client_program),
                Client_program[ClientID] = CurrentClient
                    && RELATED(Program_Level[prle_listname]) = "Program3"
            )
        )
    VAR HasOtherPrograms =
        CALCULATE(
            COUNTROWS(Client_program),
            FILTER(
                ALL(Client_program),
                Client_program[ClientID] = CurrentClient
                    && RELATED(Program_Level[prle_listname]) <> "Program3"
            )
        )
    RETURN
        IF(HasProgram3 > 0 && HasOtherPrograms = 0, 1, 0)

    If you want to check it with date range, use below DAX to create a measure

    Program3_Only_In_Range =
    VAR RangeStart = MIN('Date'[Date])
    VAR RangeEnd = MAX('Date'[Date])
    
    VAR CurrentClient =
        SELECTEDVALUE(Client[ClientID])
    
    VAR HasProgram3InRange =
        CALCULATE(
            COUNTROWS(Client_program),
            REMOVEFILTERS('Date'),
            FILTER(
                ALL(Client_program),
                Client_program[ClientID] = CurrentClient
                    && RELATED(Program_Level[prle_listname]) = "Program3"
                    && Client_program[start_date] <= RangeEnd
                    && (
                        ISBLANK(Client_program[end_date])
                        || Client_program[end_date] >= RangeStart
                    )
            )
        )
    
    VAR HasOtherPrograms =
        CALCULATE(
            COUNTROWS(Client_program),
            REMOVEFILTERS('Date'),
            FILTER(
                ALL(Client_program),
                Client_program[ClientID] = CurrentClient
                    && RELATED(Program_Level[prle_listname]) <> "Program3"
            )
        )
    
    RETURN
        IF(HasProgram3InRange > 0 && HasOtherPrograms = 0, 1, 0)

    🌟 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 SuperUserand 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!