Forum Discussion

MaxSchrijen23's avatar
4 years ago
Solved

Calculated column on date range

Hi Guys, At the moment I am really struggling with the following, any help would be appreciated.   As input data I have a table that looks like the following, it stores for each project a value fo...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi  MaxSchrijen23 ,

    I created a sample pbix file(see attachment) for you, please check whether that is what you want. Please create a measure as below, since you want the values change base on the date slicer selections....

    Measure = 
    VAR _selproject =
        SELECTEDVALUE ( 'Table'[ProjectName] )
    VAR _selcat =
        SELECTEDVALUE ( 'Table'[Category] )
    VAR _mindate =
        CALCULATE (
            MIN ( 'Table'[ChangeDate] ),
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[ProjectName] = _selproject
                    && 'Table'[Category] = _selcat
            )
        )
    VAR _maxdate =
        CALCULATE (
            MAX ( 'Table'[ChangeDate] ),
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[ProjectName] = _selproject
                    && 'Table'[Category] = _selcat
            )
        )
    VAR _mindvalue =
        CALCULATE (
            MAX ( 'Table'[Value] ),
            FILTER (
                'Table',
                'Table'[ProjectName] = _selproject
                    && 'Table'[Category] = _selcat
                    && 'Table'[ChangeDate] = _mindate
            )
        )
    VAR _maxdvalue =
        CALCULATE (
            MAX ( 'Table'[Value] ),
            FILTER (
                'Table',
                'Table'[ProjectName] = _selproject
                    && 'Table'[Category] = _selcat
                    && 'Table'[ChangeDate] = _maxdate
            )
        )
    RETURN
        SWITCH (
            TRUE (),
            _mindvalue = "Red"
                && _maxdvalue = "Green", "Up",
            _mindvalue = "Green"
                && _maxdvalue = "Red", "Down",
            _mindvalue = _maxdvalue, "Same"
        )

    And you can review the following links to get more details on the difference between calculated column and measure.

    Calculated Columns and Measures in DAX

    Calculated Columns vs Measures

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards