Forum Discussion

AllanBerces's avatar
AllanBerces
Post Prodigy
1 year ago
Solved

Combine Column

Hi good day, pls can anyone help me on my table how can i get the result i required.   DESIRED OUTPUT   Thank you
  • danextian's avatar
    1 year ago

    Hi AllanBerces 

     

    While this is very possible in DAX, the calculation won't update with new columns as each column has to be manually referenced and if a colum that's been referenced is deleted, the calc table will return an error.

    UnpivotDAX = 
    VAR _job =
        DISTINCT ( SourceTable[Job] )
    VAR _jobyr =
        CROSSJOIN ( _job, SELECTCOLUMNS ( { 2024, 2025 }, "Year", [Value] ) )
    VAR _earned =
        ADDCOLUMNS (
            _jobyr,
            "Earned",
                VAR _job = [Job]
                VAR _2024 =
                    SUMX ( FILTER ( SourceTable, [Job] = _job ), [Earned_2024] )
                VAR _2025 =
                    SUMX ( FILTER ( SourceTable, [Job] = _job ), [Earned_2025] )
                RETURN
                    SWITCH ( [Year], 2024, _2024, 2025, _2025 )
        )
    RETURN
        FILTER ( _earned, NOT ( ISBLANK ( [Earned] ) ) )