Commit ac2b741f authored by Powell, Eric's avatar Powell, Eric
Browse files

Added new files for Phase II proposal, text file with DAX/mQuery logic for F&O Pilot project

parent c28a7464
Loading
Loading
Loading
Loading
+26 KiB

File added.

No diff preview for this file type.

+1000 KiB

File added.

No diff preview for this file type.

+108 −0
Original line number Diff line number Diff line
--Get the properly formatted name (should work >90% of the time) based on the info in the Estimate

Formatted Lookup Name = 
-- Clean the input value once at the very beginning.
VAR CurrentIdentifier = TRIM ( total_labor[full_name] )

-- --- Priority 1: Check if it's a direct match for a Cost Center ---
VAR CostCenterMatch =
    LOOKUPVALUE (
        'wagepool_rates'[CostCtr],
        'wagepool_rates'[CostCtr],
        CurrentIdentifier
    )

-- --- Priority 2: If not a Cost Center, check for the longest partial match in the Name field ---
VAR PartialMatchName =
    -- Find all rows in 'wagepool_rates' where the 'Name' is a prefix.
    VAR AllPrefixMatches =
        FILTER (
            wagepool_rates, LEFT ( CurrentIdentifier, LEN ( 'wagepool_rates'[Name] ) ) = 'wagepool_rates'[Name])
            --STARTSWITH ( CurrentIdentifier, 'wagepool_rates'[Name] ))
    -- From all the matches, isolate the single best match by finding the one with the longest name.
    VAR LongestMatch =
        TOPN (
            1,
            AllPrefixMatches,
            LEN ( 'wagepool_rates'[Name] ),
            DESC
        )
    -- Extract the name from that single best-match row.
    RETURN
        MINX ( LongestMatch, 'wagepool_rates'[Name] )

-- --- Priority 3: If no other match, assume it's a person's name and reformat it ---
VAR FormattedPersonName =
    VAR CommaPosition = FIND ( ",", CurrentIdentifier, 1, -1 )
    RETURN
        IF (
            CommaPosition > 0,
            CurrentIdentifier, -- Already formatted
            VAR FirstSpace = SEARCH ( " ", CurrentIdentifier, 1, -1 )
            RETURN
                IF (
                    FirstSpace = -1,
                    BLANK (), -- Can't parse
                    VAR SecondSpace = SEARCH ( " ", CurrentIdentifier, FirstSpace + 1, -1 )
                    RETURN
                        IF (
                            SecondSpace = -1, -- "First Last"
                            VAR LastName = RIGHT ( CurrentIdentifier, LEN ( CurrentIdentifier ) - FirstSpace )
                            VAR FirstName = LEFT ( CurrentIdentifier, FirstSpace - 1 )
                            RETURN
                                LastName & ", " & FirstName,
                            -- "First MI Last"
                            VAR LastName = RIGHT ( CurrentIdentifier, LEN ( CurrentIdentifier ) - SecondSpace )
                            VAR FirstName = LEFT ( CurrentIdentifier, FirstSpace - 1 )
                            VAR MiddleInitial = MID ( CurrentIdentifier, FirstSpace + 1, SecondSpace - FirstSpace - 1 )
                            RETURN
                                LastName & ", " & FirstName & " " & MiddleInitial
                        )
                )
        )
-- --- Final Logic: Return the first successful result in order of priority ---
RETURN
    COALESCE ( CostCenterMatch, PartialMatchName, FormattedPersonName )
    

-- Using the value from above, lookup the proper rate based on name->wagepool from personnel OR wagepool from the formattedname column

    Rate = 
-- Use the clean lookup column as the key.
VAR LookupKey = 'total_labor'[Formatted Lookup Name]

-- 1. First, attempt a direct lookup in the wagepool_rates table.
VAR DirectRateLookup =
    LOOKUPVALUE (
        'wagepool_rates'[FY_2026], -- Return this rate
        'wagepool_rates'[Name],    -- Search this column
        LookupKey
    )

-- 2. If the direct lookup fails, begin the chained fallback logic.
VAR FallbackRateLookup =
    -- Step A: Look up the person's name to find their Wage Pool identifier.
    VAR WagePoolIdentifier =
        LOOKUPVALUE (
            'personnel'[Personnel.Wage Pool],              -- Get this identifier
            personnel[Personnel.Lastname_First_Middle_Hier],
            LookupKey
        )
    -- Step B: Use that identifier to look up the final rate in the wagepool_rates table.
    VAR FinalRate =
        IF (
            NOT ISBLANK ( WagePoolIdentifier ),
            LOOKUPVALUE (
                'wagepool_rates'[FY_2026], -- Return the final rate
                'wagepool_rates'[CostCtr],    -- By searching the Name column
                WagePoolIdentifier         -- For the identifier found in Step A
            )
        )
    RETURN
        FinalRate

-- Return the first rate that was successfully found.
RETURN
    COALESCE ( DirectRateLookup, FallbackRateLookup )