Forum Discussion

cheid_4838's avatar
cheid_4838
Helper IV
1 year ago
Solved

Subtracting Measure from Calculated Column

I have a table that lists out trucks and their individual operational dates.  I want to distinctcount the Ops Dates and subtract that from the number of days per month from my calendar table to show ...
  • johnt75's avatar
    1 year ago

    If you have a date table linked to your main table, you can create a measure like

    Num Days Not Running =
    VAR WorkingDates =
        DISTINCT ( 'Table'[Start Date] )
    VAR AllDates =
        VALUES ( 'Date'[Date] )
    VAR Result =
        COUNTROWS ( EXCEPT ( AllDates, WorkingDates ) )
    RETURN
        Result
    

    That should work no matter what level of the date hierarchy you are at.

  • johnt75's avatar
    johnt75
    1 year ago

    You can wrap the whole lot in an iterator over the tractors, e.g.

    Num Days Not Running =
    SUMX (
        VALUES ( 'Table'[Tractor Number] ),
        VAR WorkingDates =
            DISTINCT ( 'Table'[Start Date] )
        VAR AllDates =
            VALUES ( 'Date'[Date] )
        VAR Result =
            COUNTROWS ( EXCEPT ( AllDates, WorkingDates ) )
        RETURN
            Result
    )