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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request 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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.