Forum Discussion

Jules___'s avatar
Jules___
Frequent Visitor
2 years ago
Solved

DAX code to create calculated column based on multiple criteria

Hi I am struggling with creating a calculated colum to show some data  - i need it to be a calculated colum rather than a measure as I want to use the results in a map with conditional formatting.  ...
  • Jihwan_Kim's avatar
    2 years ago

    Hi,

    Please check the below picture and the attached pbix file.

    It is for creating a new table.

     

     

    GROUPBY function (DAX) - DAX | Microsoft Learn

     

    TREATAS function - DAX | Microsoft Learn

     

    expected result table = 
    VAR _condition =
        GROUPBY (
            data,
            data[location],
            data[question category],
            "@maxdate", MAXX ( CURRENTGROUP (), data[date] )
        )
    VAR _t =
        CALCULATETABLE (
            data,
            TREATAS ( _condition, data[location], data[question category], data[date] )
        )
    RETURN
        ADDCOLUMNS (
            SUMMARIZE ( _t, data[location], data[question category], data[date] ),
            "@ScoreSum", CALCULATE ( SUM ( data[score] ) )
        )