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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Sum column between two dates in a measure

Hi,

 

I want to create a measure to sum a column between two dates.

I have a column (ColumnDaysCount) that does the same thing but I heard that having measures instead of columns is better.

I tried to copy/paste the formulae from my column to a new measure, which did not work:

DaysSum := 
CALCULATE (
    COUNT ( DimDate[Date] );
    FILTER (
        DimDate;
        DimDate[Date] >= 'Table'[Opened]
            && DimDate[Date] <= 'Table'[Closed]
            && DimDate[Workday] = 1
    )
)

I get the error that the measure cannot make a reference to a single value from ’Table’[Opened] and ’Table’[Closed]; I understand it.

 

Then I saw this from a measure developped by someone before me and it was giving the same result as the column ColumnDaysCount :

DaysSum := 
SUMX (
    FILTER (
        DimDate;
        DimDate[Date] >= MIN( 'Table'[Opened] )
            && DimDate[Date] <= MAX( 'Table'[Closed] )
            && DimDate[Workday] = 1
    );
    DimDate[Workday]
)

CaptureDaysSum.PNG

 

Why does the MIN() and MAX() resolve the problem? Does the measure sum the result for all rows or does it calculates the sum for every ID from the moment I put it in the visualisation?

 

Can you give me keys to understand this?

Thank you,

1 REPLY 1
Nathaniel_C
Community Champion
Community Champion

Hi @Anonymous ,

My understanding is this: When you have the DAX in a calculated column, it knows where it is and what to do using row context.  However when you have it in a measure there is no row context.  The MIN() and MAX () and some other aggregators give the DAX the position (at the top or the bottom, if you will) of the column.  Thus it works even if it is in a card.  However, written correctly it also works when you filter it on a matrix or table.  Pretty amazing!

 

Not sure if that was the best explanation...anyone else?

 

Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.