Commit 952c5f74 authored by Powell, Eric's avatar Powell, Eric
Browse files

Added Basics of PowerBI model to version control

parent ac2b741f
Loading
Loading
Loading
Loading
+345 −0
Original line number Diff line number Diff line
// Table Definition Queries

-- BIF_PALS_Labor

let
    Source = AnalysisServices.Databases("prdbi", [TypedMeasureColumns=true, Implementation="2.0"]),
    Finance_Reporting = Source{[Name="Finance_Reporting"]}[Data],
    #"BI FINANCE DWReporting1" = Finance_Reporting{[Id="BI FINANCE DWReporting"]}[Data],
    #"BI FINANCE DWReporting2" = #"BI FINANCE DWReporting1"{[Id="BI FINANCE DWReporting"]}[Data],
    #"Added Items" = Cube.Transform(#"BI FINANCE DWReporting2",
        {
            {Cube.AddMeasureColumn, "Hours", "[Measures].[Hours]"},
            {Cube.AddAndExpandDimensionColumn, "[Order Master]", {"[Order Master].[Charge Number IO].[Charge Number IO]"}, {"Order Master.Charge Number IO"}},
            {Cube.AddAndExpandDimensionColumn, "[Personnel]", {"[Personnel].[Active Flag].[Active Flag]", "[Personnel].[Lastname First Middle Hier].[Lastname First Middle Hier]"}, {"Personnel.Active Flag", "Personnel.Lastname First Middle Hier"}},
            {Cube.AddMeasureColumn, "Labor Amount", "[Measures].[Labor Amount]"},
            {Cube.AddMeasureColumn, "Labor W Org Burden & Ovh", "[Measures].[Labor W Org Burden & Ovh]"}
        }),
    #"Filtered Rows1" = Table.SelectRows(#"Added Items", each (Cube.AttributeMemberId([Personnel.Active Flag]) <> "[Personnel].[Active Flag].&[N]" meta [DisplayName = "N"])),
    #"Filtered Rows" = Table.SelectRows(#"Filtered Rows1", each (Cube.AttributeMemberId([Order Master.Charge Number IO]) <> "[Order Master].[Charge Number IO].&[99999999]" meta [DisplayName = "99999999"]))
in
    #"Filtered Rows"
    
-- MSL_Feature_Prioritization
let
    Source = SharePoint.Tables("https://ornl.sharepoint.com/sites/FOIntegratedServices", [Implementation="2.0", ViewMode="All"]),
    #"7775fb23-eccf-4583-8770-2b7f286661ba" = Source{[Id="7775fb23-eccf-4583-8770-2b7f286661ba"]}[Items],
    #"Removed Columns" = Table.RemoveColumns(#"7775fb23-eccf-4583-8770-2b7f286661ba",{"Alignment", "Demand", "Lifespan", "Immediacy", "Savings", "Impact", "Urgency", "Risk Reduction", "Effort", "Dependencies", "Requirements Maturity", "Risk", "Color Tag", "Compliance Asset Id", "Attachments", "align_val", "dem_val", "lifespan_val", "immed_val", "sav_val", "impact_val", "urg_val", "rskred_val",  "dep_val", "reqmat_val", "risk_val", "ID", "Content Type", "Created By", "Modified By", "Version", "Edit", "Type", "Item Child Count", "Folder Child Count", "Label setting", "Retention label", "Retention label Applied", "Label applied by", "Item is a Record", "App Created By", "App Modified By"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"effort_val", "EffortValue"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Difficulty and Risk Score", type number}, {"Rank", type number}, {"EffortValue", type number}, {"Strategic Dimension Score", type number}, {"Impact Dimension Score", type number}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Platform", Order.Ascending}})
in
    #"Sorted Rows"

-- MSL Metadata
let
    Source = SharePoint.Tables("https://ornl.sharepoint.com/sites/FOIntegratedServices", [Implementation="2.0", ViewMode="All"]),
    #"7775fb23-eccf-4583-8770-2b7f286661ba" = Source{[Id="7775fb23-eccf-4583-8770-2b7f286661ba"]}[Items],
    #"Removed Columns" = Table.RemoveColumns(#"7775fb23-eccf-4583-8770-2b7f286661ba",{"Alignment", "Demand", "Lifespan", "Immediacy", "Savings", "Impact", "Urgency", "Risk Reduction", "Effort", "Dependencies", "Requirements Maturity", "Risk", "Color Tag", "Compliance Asset Id", "Attachments", "Strategic Dimension Score", "Impact Dimension Score", "Difficulty and Risk Score", "Rank", "align_val", "dem_val", "lifespan_val", "immed_val", "sav_val", "impact_val", "urg_val", "rskred_val", "effort_val", "dep_val", "reqmat_val", "risk_val"})
in
    #"Removed Columns"
    
    
 -- MSL_Metadata
 
 let
    Source = SharePoint.Tables("https://ornl.sharepoint.com/sites/FOIntegratedServices", [Implementation="2.0", ViewMode="All"]),
    #"7775fb23-eccf-4583-8770-2b7f286661ba" = Source{[Id="7775fb23-eccf-4583-8770-2b7f286661ba"]}[Items],
    #"Removed Columns" = Table.RemoveColumns(#"7775fb23-eccf-4583-8770-2b7f286661ba",{"Feature Description", "Requestor", "Request Date", "Internal Order (IO) Number", "Alignment", "Demand", "Lifespan", "Immediacy", "Savings", "Impact", "Urgency", "Risk Reduction", "Effort", "Dependencies", "Requirements Maturity", "Risk", "Color Tag", "Compliance Asset Id", "Platform", "Primary Resource", "Secondary Resource", "Hard Deadline", "Funding", "Tool Dependencies", "ID", "Content Type", "Modified", "Created"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"effort_val", type number}, {"Rank", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "effort_wt", each [effort_val]/5),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "mgmt_wt", each 5-([Management Priority Rank] ?? 5)),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"mgmt_wt", Int64.Type}}),
    #"Added Custom2" = Table.AddColumn(#"Changed Type1", "mgt_weighted_rank", each [Rank]+[mgmt_wt]),
    #"Changed Type2" = Table.TransformColumnTypes(#"Added Custom2",{{"mgt_weighted_rank", type number}})
in
    #"Changed Type2"
    
--Res_Activity_Schedule
let
    Source = PostgreSQL.Database("hgis-prj-mgmt:5438", "proj_status"),
    fo_itsd_estimate_vext_activity_schedule = Source{[Schema="fo_itsd_estimate",Item="vext_activity_schedule"]}[Data]
in
    fo_itsd_estimate_vext_activity_schedule
    
-- Res_WeeklyLabor_Pivot

let
    Source = PostgreSQL.Database("hgis-prj-mgmt:5438", "proj_status"),
    fo_itsd_estimate_v_labor_plan_data = Source{[Schema="fo_itsd_estimate",Item="v_labor_plan_data"]}[Data],
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(fo_itsd_estimate_v_labor_plan_data, {{"the_date", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(fo_itsd_estimate_v_labor_plan_data, {{"the_date", type text}}, "en-US")[the_date]), "the_date", "fte")
in
    #"Pivoted Column"

-- RES_Task_Schedule

let
    Source = PostgreSQL.Database("hgis-prj-mgmt:5438", "proj_status"),
    fo_itsd_estimate_vext_task_schedule = Source{[Schema="fo_itsd_estimate",Item="vext_task_schedule"]}[Data]
in
    fo_itsd_estimate_vext_task_schedule

-- RES_estimated_labor
let
    Source = PostgreSQL.Database("hgis-prj-mgmt:5438", "proj_status"),
    fo_itsd_estimate_v_labor_plan_data = Source{[Schema="fo_itsd_estimate",Item="v_labor_plan_data"]}[Data]
in
    fo_itsd_estimate_v_labor_plan_data
    
 -- BIF_PALS_Labor
 let
    Source = AnalysisServices.Databases("prdbi", [TypedMeasureColumns=true, Implementation="2.0"]),
    Finance_Reporting = Source{[Name="Finance_Reporting"]}[Data],
    #"BI FINANCE DWReporting1" = Finance_Reporting{[Id="BI FINANCE DWReporting"]}[Data],
    #"BI FINANCE DWReporting2" = #"BI FINANCE DWReporting1"{[Id="BI FINANCE DWReporting"]}[Data],
    #"Added Items" = Cube.Transform(#"BI FINANCE DWReporting2",
        {
            {Cube.AddMeasureColumn, "Hours", "[Measures].[Hours]"},
            {Cube.AddAndExpandDimensionColumn, "[Order Master]", {"[Order Master].[Charge Number IO].[Charge Number IO]"}, {"Order Master.Charge Number IO"}},
            {Cube.AddAndExpandDimensionColumn, "[Personnel]", {"[Personnel].[Active Flag].[Active Flag]", "[Personnel].[Lastname First Middle Hier].[Lastname First Middle Hier]"}, {"Personnel.Active Flag", "Personnel.Lastname First Middle Hier"}},
            {Cube.AddMeasureColumn, "Labor Amount", "[Measures].[Labor Amount]"},
            {Cube.AddMeasureColumn, "Labor W Org Burden & Ovh", "[Measures].[Labor W Org Burden & Ovh]"}
        }),
    #"Filtered Rows1" = Table.SelectRows(#"Added Items", each (Cube.AttributeMemberId([Personnel.Active Flag]) <> "[Personnel].[Active Flag].&[N]" meta [DisplayName = "N"])),
    #"Filtered Rows" = Table.SelectRows(#"Filtered Rows1", each (Cube.AttributeMemberId([Order Master.Charge Number IO]) <> "[Order Master].[Charge Number IO].&[99999999]" meta [DisplayName = "99999999"]))
in
    #"Filtered Rows"

-- SAP_orgburden_rates
let
    Source = Csv.Document(File.Contents("C:\Users\uvp\OneDrive - Oak Ridge National Laboratory\Project Management\PMO\PowerBI_Temaple 3.7_with_data_files\orgburden_rates.txt"),[Delimiter="	", Columns=7, Encoding=1200, QuoteStyle=QuoteStyle.None]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{" Div ", type text}, {" Cost Ctr ", type text}, {" Name ", type text}, {" FY 2026 ", type number}, {" FY 2027 ", type number}, {" FY 2028 ", type number}, {" ", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{" "})
in
    #"Removed Columns"

-- BIF_personnel

let
    Source = AnalysisServices.Databases("prdbi", [TypedMeasureColumns=true, Implementation="2.0"]),
    Finance_Reporting = Source{[Name="Finance_Reporting"]}[Data],
    #"BI FINANCE DWReporting1" = Finance_Reporting{[Id="BI FINANCE DWReporting"]}[Data],
    #"BI FINANCE DWReporting2" = #"BI FINANCE DWReporting1"{[Id="BI FINANCE DWReporting"]}[Data],
    #"Added Items" = Cube.Transform(#"BI FINANCE DWReporting2",
        {
            {Cube.AddAndExpandDimensionColumn, "[Personnel]", {"[Personnel].[Wage Pool].[Wage Pool]", "[Personnel].[Lastname First Middle Hier].[Lastname First Middle Hier]"}, {"Personnel.Wage Pool", "Personnel.Lastname First Middle Hier"}}
        }),
    #"Renamed Columns" = Table.RenameColumns(#"Added Items",{{"Personnel.Lastname First Middle Hier", "Personnel.Lastname_First_Middle_Hier"}}),
    #"Filtered Rows" = Table.SelectRows(#"Renamed Columns", each (Cube.AttributeMemberId([Personnel.Wage Pool]) <> "[Personnel].[Wage Pool].&[Unknown]" meta [DisplayName = "Unknown"]))
in
    #"Filtered Rows"


-- SAP_wagepool_rates

 let
    Source = Csv.Document(File.Contents("C:\Users\uvp\OneDrive - Oak Ridge National Laboratory\Project Management\PMO\PowerBI_Temaple 3.7_with_data_files\wagepool_rates.txt"),[Delimiter="	", Columns=6, Encoding=1200, QuoteStyle=QuoteStyle.None]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{" Cost Ctr ", type text}, {" Name ", type text}, {" FY 2026 ", type number}, {" FY 2027 ", type number}, {" FY 2028 ", type number}, {" ", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{" FY 2026 ", "FY_2026"}, {" FY 2027 ", "FY_2027"}, {" FY 2028 ", "FY_2028"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{" "}),
    #"Renamed Columns1" = Table.RenameColumns(#"Removed Columns",{{" Cost Ctr ", "CostCtr"}, {" Name ", "Name"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns1",{{"FY_2026", Currency.Type}}),
    #"Trimmed Text" = Table.TransformColumns(#"Changed Type1",{{"Name", Text.Trim, type text}, {"CostCtr", Text.Trim, type text}})
in
    #"Trimmed Text"

-- DAX_Weekly_Cost
weekly_cost = 
VAR cost_table =
    ADDCOLUMNS(
        'PG_estimated_cost',
        "Duration", LOOKUPVALUE(
            'PG_estimated duration'[weighted_duration_months],
            'PG_estimated duration'[title],
            'PG_estimated_cost'[title]
        ),
        "Cost per Week", DIVIDE(
            'PG_estimated_cost'[weighted_cost],
            LOOKUPVALUE(
                'PG_estimated duration'[weighted_duration_days],
                'PG_estimated duration'[title],
                'PG_estimated_cost'[title]
            )
        ) * 5
    )

RETURN
    cost_table


// Custom DAX measures

-- RES_estimated_labor

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

-- --- Priority 1: Check if it's a direct match for a Cost Center ---
VAR CostCenterMatch =
    LOOKUPVALUE (
        'SAP_wagepool_rates'[CostCtr],
        'SAP_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 (
            SAP_wagepool_rates, LEFT ( CurrentIdentifier, LEN ( 'SAP_wagepool_rates'[Name] ) ) = 'SAP_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 ( 'SAP_wagepool_rates'[Name] ),
            DESC
        )
    -- Extract the name from that single best-match row.
    RETURN
        MINX ( LongestMatch, 'SAP_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 )

-- Rate Measure

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

-- 1. First, attempt a direct lookup in the wagepool_rates table.
VAR DirectRateLookup =
    LOOKUPVALUE (
        'SAP_wagepool_rates'[FY_2026], -- Return this rate
        'SAP_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 (
            'BIF_personnel'[Personnel.Wage Pool],              -- Get this identifier
            BIF_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 (
                'SAP_wagepool_rates'[FY_2026], -- Return the final rate
                'SAP_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 )

-- Running Total Cost

Running Total Cost = 
CALCULATE (
    SUM ( RES_estimated_labor[weekly_cost] ),
    FILTER (
        ALL ( RES_estimated_labor[the_date] ),
        RES_estimated_labor[the_date] <= MAX ( RES_estimated_labor[the_date] )
    )
)

-- Running Total Labor

Running Total Labor Hours = 
CALCULATE (
    SUM ( RES_estimated_labor[fte] ),
    FILTER (
        ALL ( RES_estimated_labor[the_date] ),
        RES_estimated_labor[the_date] <= MAX ( RES_estimated_labor[the_date] )
    )
)



-- Weekly Cost

weekly_cost = RES_estimated_labor[fte]*RES_estimated_labor[Rate] *40


-- Running Total Labor Cost
Running Total Cost = 
CALCULATE (
    SUM ( RES_estimated_labor[weekly_cost] ),
    FILTER (
        ALL ( RES_estimated_labor[the_date] ),
        RES_estimated_labor[the_date] <= MAX ( RES_estimated_labor[the_date] )
    )
)

-- Summarize PALS Labor Data to plot on a timeseries
DAX_PALS_Labor_Summary = 
SUMMARIZE(
    FILTER(
        BIF_PALS_LABOR,
        BIF_PALS_LABOR[Order Master.Charge Number IO] = "M5381815"
    ),
    BIF_PALS_LABOR[Labor W Org Burden & Ovh],
    BIF_PALS_LABOR[Date.DateMDY],
    BIF_PALS_LABOR[Order Master.Charge Number IO]
)

-- Running Total Labor Cost (PALS Labor)

Runnng_Total_Cost = CALCULATE (
    SUM ( DAX_PALS_Labor_Summary[Labor W Org Burden & Ovh] ),
    FILTER (
        ALL ( DAX_PALS_Labor_Summary[Date.DateMDY] ),
        DAX_PALS_Labor_Summary[Date.DateMDY] <= MAX (DAX_PALS_Labor_Summary[Date.DateMDY] )
    )
)



+10 −0
Original line number Diff line number Diff line
Running Total Cost	[Measures].[Running Total Cost]	Running Total Cost

CALCULATE (
    SUM ( RES_estimated_labor[weekly_cost] ),
    FILTER (
        ALL ( DAX_Dates[cal_date] ),
        DAX_Dates[cal_date] <= MAX ( DAX_Dates[cal_date] )
    )
)
+14 −0
Original line number Diff line number Diff line

Running Total Labor Hours	[Measures].[Running Total Labor Hours]	Running Total Labor Hours

EXPRESSION
CALCULATE (
    SUM ( RES_estimated_labor[fte] ),
    FILTER (
        ALL ( RES_estimated_labor[the_date] ),
        RES_estimated_labor[the_date] <= MAX ( RES_estimated_labor[the_date] )
    )
)


+160 B

File added.

No diff preview for this file type.

+170 B

File added.

No diff preview for this file type.

Loading