Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
cheid_4838
Helper IV
Helper IV

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 how many days per week, month, and year the trucks were not running.  I am not sure how to subtract a days per month column from the distinctcount of operational dates.  Is there anyway to create a measure of days per month?  Any help you can provide is appreciated.

 

cheid_4838_0-1747311157378.png

 

2 ACCEPTED SOLUTIONS
johnt75
Super User
Super User

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.

View solution in original post

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
)

View solution in original post

3 REPLIES 3
johnt75
Super User
Super User

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.

John,

Thanks for your help. That solution worked when I pulled in the tractor number, but it doesn't work when I put the value in a card.  When I put number of days not running in a car for a week period I only show 1 day not running.  I know that is not correct.  How can I get this to work where I can sum the number of days remaining regardless of the visual or data point that is pulled in? Thanks.  

 

 

 

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
)

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors