Search code examples
powerbidaxdata-analysispowerbi-desktopmeasure

Replacing Colour Values with Related Column Values of a declared Table


_Hi, I have the following DAX measure and I would like to replace the XXXX section by the related colour of the "@Colour" column from the same _BarTable. I don't know how to do it ? Thanks for your help ! Link to Pbix file

VAR _BarTable=
    ADDCOLUMNS(
        SUMMARIZE('Crypto Data', 'Crypto Data'[timestamp]),
        "@Colour", IF(
                    [Current Price] = _YMaxValue, "Green",
                    IF( [Current Price] = _YMinValue, "Red",
                    _LineColor)
                   ),
        "@Bars",    "<rect x='" & INT(150 * DIVIDE('Crypto Data'[timestamp] - _XMinDate, _XMaxDate - _XMinDate)) &
                    "' width='1' stroke='" & XXXX & "' stroke-width='1' y='" &
                    50 -  INT(50 * DIVIDE([Current Price] - _YMinValue, _YMaxValue - _YMinValue)) & "' height='" &
                    INT(50 * DIVIDE([Current Price] - _YMinValue, _YMaxValue - _YMinValue)) &
                    "'  style='fill:" & XXXX & "'/>"
    )

Solution

  • Try this.

    VAR _BarTable=
        ADDCOLUMNS(
            SUMMARIZE('Crypto Data', 'Crypto Data'[timestamp]),
    
            "@Colour", IF(
                        [Current Price] = _YMaxValue, "Green",
                        IF( [Current Price] = _YMinValue, "Red",
                        _LineColor)
                       ),
        
            "@Bars",   
             
             VAR x = IF(
                        [Current Price] = _YMaxValue, "Green",
                        IF( [Current Price] = _YMinValue, "Red",
                        _LineColor)
                       )
             RETURN
             "<rect x='" & INT(150 * DIVIDE('Crypto Data'[timestamp] - _XMinDate, _XMaxDate - _XMinDate)) &
                        "' width='1' stroke='" & x & "' stroke-width='1' y='" &
                        50 -  INT(50 * DIVIDE([Current Price] - _YMinValue, _YMaxValue - _YMinValue)) & "' height='" &
                        INT(50 * DIVIDE([Current Price] - _YMinValue, _YMaxValue - _YMinValue)) &
                        "'  style='fill:" & x & "'/>"
        )