Search code examples
powerbidaxdata-analysispowerbi-desktopmeasure

Using a DAX Count rows / Treatas measure with a subtraction element


I'm very new to DAX but I'm trying to increase my understanding on a daily basis. My current problem is that I have the following measure that allows me to show a running count of activities in a table. The data revolves around the period a piece of data was added. This works fine but i'd also like to subtract from the count the number of cancellations in that period which is in the same table under the column 'cancelled'. The enteries in the 'cancelled' column also show the period when the item was cancelled, such as 'T-3, T-2' ETC Can anyone help me with this subtraction element?

CountValues T-1 = 
 CALCULATE (
    COUNTROWS ( '2024-24 RAG Data' ),
    KEEPFILTERS (
        TREATAS ( { "T-4", "T-3", "T-2","T-1"}, '2024-24 RAG Data'[Period Sumitted] )
    ))

Solution

  • Is it not just this?

    CountValues T-1 = 
    
    VAR a = CALCULATE (
        COUNTROWS ( '2024-24 RAG Data' ),
        KEEPFILTERS (
            TREATAS ( { "T-4", "T-3", "T-2","T-1"}, '2024-24 RAG Data'[Period Sumitted] )
        ))
        
    VAR b = CALCULATE (
        COUNTROWS ( '2024-24 RAG Data' ),
        KEEPFILTERS (
            TREATAS ( { "T-4", "T-3", "T-2","T-1"}, '2024-24 RAG Data'[Cancelled] )
        ))
    
    RETURN a - b