Forum Discussion

ashmitp869's avatar
ashmitp869
Icon for Responsive Resident rankResponsive Resident
11 months ago
Solved

Help with the dax Formula- ApprovedStdCost

Hi All, I have a requirement like below. Please help me with the dax formula. For Project NOT EQUAL 1 then keep the same logic of ApprovedStdCost Else When ProjectRateCodeDescription is NU...
  • GrowthNatives's avatar
    GrowthNatives
    11 months ago

    Hi ashmitp869 , 
    You can try these steps to get the result 
    Detects “Project = 1” whether Project is numeric or text like “1 A”.
    Applies the FY=2025 override only when Project=1 and ProjectRateCodeDescription is blank.

    Uses TREATAS for stable, row-level filters.

    DAX
    ApprovedStdCostDynamic_DateBased :=
    VAR ApprovedRows =
        FILTER (
            Plan_DailyPlanHoursResourceVersion,
            Plan_DailyPlanHoursResourceVersion[DailyPlanStatusDescription] = "Approved"
        )
    RETURN
    SUMX (
        ApprovedRows,
        VAR StdHours      = Plan_DailyPlanHoursResourceVersion[ApprovedStdHours]
        VAR ResourceType  = Plan_DailyPlanHoursResourceVersion[ResourceType]
        VAR ProjectRaw    = Plan_DailyPlanHoursResourceVersion[ProjectId]
    
        /* Project = 1 check works for both numeric and text like "1 A" */
        VAR IsProject1 :=
            IF (
                ISNUMBER ( ProjectRaw ),
                ProjectRaw = 1,
                LEFT ( FORMAT ( ProjectRaw, "" ), 1 ) = "1"
            )
    
        /* Rates from related tables / BT lookups */
        VAR EquipRate          = RELATED ( Core_ProjectEquipment[UnitCost] )
        VAR BTKey              = Plan_DailyPlanHoursResourceVersion[Key]
        VAR DefaultRateCodeId  = LOOKUPVALUE ( BT[DefaultProjectRateCodeId], BT[Key], BTKey )
        VAR CraftDesc          = LOOKUPVALUE ( BT[Craft], BT[Key], BTKey )
        VAR MatchRateCodeDesc  = CraftDesc & " BASE"
        VAR PRCD               = Plan_DailyPlanHoursResourceVersion[ProjectRateCodeDescription]
    
        /* Normal resolution paths */
        VAR StdRate_RateCode :=
            CALCULATE (
                MAX ( Core_ProjectRateCode[StraightTimeRate] ),
                TREATAS ( { DefaultRateCodeId }, Core_ProjectRateCode[ProjectRateCodeId] )
            )
    
        VAR StdRate_Craft :=
            CALCULATE (
                MAX ( Core_ProjectRateCode[StraightTimeRate] ),
                TREATAS ( { MatchRateCodeDesc }, Core_ProjectRateCode[ProjectRateCodeDescription] )
            )
    
        VAR StdRate_Emp = RELATED ( Core_ProjectEmployee[StraightTimeRate] )
    
        /* Build a reusable filter for the override */
        VAR OverrideFilter :=
            IF (
                NOT ISBLANK ( DefaultRateCodeId ),
                TREATAS ( { DefaultRateCodeId }, Core_ProjectRateCode[ProjectRateCodeId] ),
                TREATAS ( { MatchRateCodeDesc }, Core_ProjectRateCode[ProjectRateCodeDescription] )
            )
    
        /* FY25 override: only when Project=1 and PRCD is blank */
        VAR StdRate_FY25_Override :=
            IF (
                IsProject1 && ( ISBLANK ( PRCD ) || PRCD = "" ),
                CALCULATE (
                    MAX ( Core_ProjectRateCode[StraightTimeRate] ),
                    REMOVEFILTERS ( Core_ProjectRateCode ),
                    OverrideFilter,
                    Core_ProjectRateCode[FY] = 2025   -- adjust if your column is named differently / text "FY25"
                )
            )
    
        /* Final rate selection (override takes priority) */
        VAR StdRate :=
            COALESCE (
                StdRate_FY25_Override,
                StdRate_RateCode,
                StdRate_Craft,
                StdRate_Emp,
                0
            )
    
        RETURN
            SWITCH (
                TRUE(),
                ResourceType = "Equipment", StdHours * EquipRate,
                ResourceType = "Labor",     StdHours * StdRate,
                0
            )
    )


    Quick checks :
    • Project field: If it truly is text like “1 A/1 B”, keep the LEFT(...)= "1" logic. If it’s numeric, you can simplify to ProjectRaw = 1.
    • Core_ProjectRateCode[FY]: confirm it’s numeric 2025 (change the filter to "FY25" if it’s text).
    • Ensure relationships for RELATED() calls are active (Plan → Core_ProjectRateCode, Plan → Core_ProjectEmployee, Plan → Core_ProjectEquipment).
    • Make sure there’s a row in Core_ProjectRateCode for the matched description (e.g., “Delivery Manager BASE”) and FY=2025; otherwise the measure will correctly fall back.

    ⭐Hope this solution helps you make the most of Power BI! If it did, click 'Mark as Solution' to help others find the right answers.
    💡Found it helpful? Show some love with kudos 👍 as your support keeps our community thriving!
    🚀Let’s keep building smarter, data-driven solutions together!🚀 [Explore More]