Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Calulate difference between columns if has numbers. Otherwise give tekst with explanation

Hi all,   I have a table with 2 columns with numbers an some nulls. I would like to create a measure in DAX wich gives me the differens (column 2019-Column 2018) if both columns have numbers. And i...
  • Anonymous's avatar
    Anonymous
    5 years ago

    HI @BobKoenen,

    The lkalawski formula looks good, but the current computed column and measure are not able to directly return multiple data types. I think you need to add some additional operations in the formula to convert them to text to avoid the data type problem. (I used the if statement to check the field values)

    Column Version =
    IF (
        [2018] = BLANK (),
        "2018 missed",
        IF ( [2019] = BLANK (), "2019 missed", [2019] - [2018] )
    ) & ""
    
    Measure version = 
    CONCATENATEX (
        SUMMARIZE (
            'Table',
            [2018],
            [2019],
            "Result",
                IF (
                    [2018] = BLANK (),
                    "2018 missed",
                    IF ( [2019] = BLANK (), "2019 missed", [2019] - [2018] )
                ) & ""
        ),
        [Result],
        ","
    )
    

    Best regards

    Xiaoxin Sheng