Forum Discussion

JustDavid's avatar
JustDavid
Helper IV
1 year ago
Solved

Multi Tier Allocation from multiple tables

I do not know if what I desired to achieve is achievable. Been trying this for a couple of days and unable to produce result.   I have 4 sources - 3 allocations tables (T1, T2 and T3 allocation) an...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi JustDavid ,

    Please follow these steps:

    1.Use the following DAX expression to create a table

    Table = 
    FILTER (
        SELECTCOLUMNS (
            mirrorFactTableWithAllCostCodes,
            "id", [id],
            "obj code", [obj code],
            "cost code", [cost code]
        ),
        [id] = "fn9401"
            || [id] = "fn9402"
    )

    2.Use the following DAX expression to create a column in table 'mirrorFactTableWithAllCostCodes'

    Column = 
    VAR _result = SUMX(RELATEDTABLE(factTable),[Budget])
    RETURN IF(ISBLANK(_result),0,_result)

    3.Use the following DAX expression to create a measure

    MEASURE =
    VAR _obj =
        SELECTEDVALUE ( 'Table'[obj code] )
    VAR _cost =
        SELECTEDVALUE ( 'Table'[cost code] )
    VAR _id =
        SELECTEDVALUE ( 'Table'[id] )
    VAR _table1 =
        ADDCOLUMNS (
            'tbl_Tier1',
            "c1",
                SUMX (
                    FILTER (
                        mirrorFactTableWithAllCostCodes,
                        [id] = EARLIER ( tbl_Tier1[T1_From] )
                            && [obj code] = _obj
                            && [cost code] = _cost
                    ),
                    [Column]
                ) * [T1_Alloc]
        )
    VAR _table2 =
        ADDCOLUMNS (
            'tbl_Tier2',
            "c1",
                VAR _result =
                    (
                        SUMX ( FILTER ( _table1, [T1_To] = EARLIER ( tbl_Tier2[T2_From] ) ), [c1] )
                            + SUMX (
                                FILTER (
                                    'mirrorFactTableWithAllCostCodes',
                                    [id] = EARLIER ( tbl_Tier2[T2_From] )
                                        && [obj code] = _obj
                                        && [cost code] = _cost
                                ),
                                [Column]
                            )
                    ) * [T2_Alloc]
                RETURN
                    IF ( ISBLANK ( _result ), 0, _result )
        )
    VAR _table3 =
        ADDCOLUMNS (
            'tbl_Tier3',
            "c1",
                VAR _result =
                    (
                        SUMX ( FILTER ( _table2, [T2_To] = EARLIER ( tbl_Tier3[T3_From] ) ), [c1] )
                            + SUMX (
                                FILTER (
                                    'mirrorFactTableWithAllCostCodes',
                                    [id] = EARLIER ( tbl_Tier3[T3_From] )
                                        && [obj code] = _obj
                                        && [cost code] = _cost
                                ),
                                [Column]
                            )
                    ) * [T3_Alloc]
                RETURN
                    IF ( ISBLANK ( _result ), 0, _result )
        )
    RETURN
        SUMX ( FILTER ( _table3, [T3_To] = _id ), [c1] )
            + SUMX (
                FILTER (
                    'mirrorFactTableWithAllCostCodes',
                    [id] = _id
                        && [cost code] = _cost
                        && [obj code] = _obj
                ),
                [Column]
            )
    

    4.Final output

     

    Best Regards