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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

How can I combine sum and countrow to obtain the accumulated number of rows across a timespan?

Hi,

 

I'm new to DAX and Power BI.


I'm working on a report for my firm, upon applications for a school.

I am using countrows to count the number of applications, and from here I want to make a graph that maps the accumulation of applications, throughout the weeks of the year.

But I'm having troubles as to how, I can sum and perform countrows in combinations?

 

I have tried varies workarounds, but I'm all stuck - and I therefore hope that someone can give me a hint 😃

 

3 ACCEPTED SOLUTIONS
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Do you mean something like this?

Icey_0-1644559739054.png

 

If so, try to create a date table and a measure like belwo:

Date = 
ADDCOLUMNS (
    CALENDAR (
        MIN ( 'Table'[Date of Application ] ),
        EOMONTH ( MAX ( 'Table'[Date of Application ] ), 0 )
    ),
    "Year", YEAR ( [Date] ),
    "Month", MONTH ( [Date] ),
    "Week", WEEKNUM ( [Date], 1 )
)
StartDate_Week = 
CALCULATE (
    MIN ( 'Date'[Date] ),
    FILTER (
        'Date',
        'Date'[Year] = EARLIER ( 'Date'[Year] )
            && 'Date'[Week] = EARLIER ( 'Date'[Week] )
    )
)

Icey_1-1644559839331.png

 

Measure = 
VAR CurrentWeek_ =
    MAX ( 'Date'[StartDate_Week] )
RETURN
    CALCULATE (
        COUNTROWS ( 'Table' ),
        'Table'[Date of Application ] <= CurrentWeek_
    )

 

Icey_3-1644559917441.png

 

Icey_2-1644559890870.png

 

 

For more details, please check the attached .pbix file.

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Icey
Community Support
Community Support

Hi @Anonymous ,

 

Create two columns and use the previous measure like below:

Icey_0-1645421415523.png

WeekNum = 
"W " & FORMAT ( [Week], "0#" )
Quarter Label = 
[Year] & " Q"
    & QUARTER ( [Date] )

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Icey
Community Support
Community Support

Hi @Anonymous ,

 

How about this?

Measure 2 =
VAR CurrentWeek_ =
    MAX ( 'Date'[StartDate_Week] )
VAR StartDate_Year =
    CALCULATE (
        MIN ( 'Date'[StartDate_Week] ),
        FILTER ( ALLSELECTED ( 'Date' ), 'Date'[Year] = MAX ( 'Date'[Year] ) )
    )
RETURN
    CALCULATE (
        COUNTROWS ( 'Table' ),
        'Table'[Date of Application ] <= CurrentWeek_,
        'Table'[Date of Application ] >= StartDate_Year
    )

Icey_1-1645494536044.png

 

Or this?

Measure 3 = 
VAR CurrentWeek_ =
    MAX ( 'Date'[StartDate_Week] )
VAR CurrentYear_ =
    MAX ( 'Date'[Year] )
RETURN
    CALCULATE (
        COUNTROWS ( 'Table' ),
        'Table'[Date of Application ] <= CurrentWeek_,
        YEAR ( 'Table'[Date of Application ] ) = CurrentYear_
    )

Icey_0-1645494517055.png

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

12 REPLIES 12
Anonymous
Not applicable

I have succeded in getting the count, for received application pr. week, using the following code:

 

Measure = countrows(FILTER(table1,table1[Studystartyear]=2022&&table1[Receivedyear]=2022))
 
But cannot figure out, how I can accumulate this, and finally add the applications received before the start of 2022 (to the accumulation). Without the applications received at the end of 2021, appearing to be received in the final weeks of 2022.
 
I have pinpointed the application for 2022 and received in 2021 using the code
Measure2 = COUNTROWS(filter(table1,table1[Studystartyear]=2022&&table1[Receivedyear]=2021))
 

@Anonymous - calculating a running total using the Week Number will cause the "appearing to be received in the final weeks of 2022".  You need to switch to using the "Start of Week" or "End of Week" on the X axis to drive the accumulation of applications.

I noted that you included Received Year in the measures.  This is also less desirable for calculating the running totals.  I would consider moving Received Year to Label in the Running Total Chart.

 

Please create the following measure:

Count of Applications = COUNTROWS(table)

Count of Applications Running Total = 
VAR LastVisibleDate = MAX ( 'Date'[Date] )
VAR Result = CALCULATE ( [Count of Applications] , calendar[Date] <= LastVisibleDate ) //relationship between [Date] and [Date of Application]
RETURN
Result

When using this measure, you need to filter for StudyYear = 2022, and filter the Start of Week Date Range 2022.  Using the Received Year as a label will highlight the applications received in earlier years.

 

This approach should allow you to change more dynamically from 2022 to 2023.

 

Anonymous
Not applicable

Thanks alot @Daryl-Lynch-Bzy ! Using week start has helped greatly and the , and I obtained the following graph 

 

Mercedes_b_2-1644324629284.png

 

 

But ideally I would like to obtain a graph mapping the accumulated number of application, throughout the year, and not the running flow/total. Is this possible somehow? 

Icey
Community Support
Community Support

Hi @Anonymous ,

 

Do you mean something like this?

Icey_0-1644559739054.png

 

If so, try to create a date table and a measure like belwo:

Date = 
ADDCOLUMNS (
    CALENDAR (
        MIN ( 'Table'[Date of Application ] ),
        EOMONTH ( MAX ( 'Table'[Date of Application ] ), 0 )
    ),
    "Year", YEAR ( [Date] ),
    "Month", MONTH ( [Date] ),
    "Week", WEEKNUM ( [Date], 1 )
)
StartDate_Week = 
CALCULATE (
    MIN ( 'Date'[Date] ),
    FILTER (
        'Date',
        'Date'[Year] = EARLIER ( 'Date'[Year] )
            && 'Date'[Week] = EARLIER ( 'Date'[Week] )
    )
)

Icey_1-1644559839331.png

 

Measure = 
VAR CurrentWeek_ =
    MAX ( 'Date'[StartDate_Week] )
RETURN
    CALCULATE (
        COUNTROWS ( 'Table' ),
        'Table'[Date of Application ] <= CurrentWeek_
    )

 

Icey_3-1644559917441.png

 

Icey_2-1644559890870.png

 

 

For more details, please check the attached .pbix file.

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks alot! 

 

This really helped out, it is exactly what I was looking for.

I have now obtained the following graph

Mercedes_b_2-1644571029118.png

but what I would really like is a graph which maps how the applications comes in throughout the weeks of the year conditional on the studystart year, in the same manor as the following graph. So that you can compare the number of incoming applications across different years, like this graph compares quaters of different years

Mercedes_b_4-1644571634545.png

The triggy part is though, that some of the applications are received in the prior year to the studystart year, but I would like these applications to be the cutting of the y-axis.

 

 

 

 

Anonymous
Not applicable

so ideally i would like a line mapping the accumulation of applications with studystart=2022, for this line the cutting with the y-áxis are apllications received in total throughout 2021, and the the applications received in 2022 are accumulating continously across weeks, until the date of today (as apllications are still being submitted for 2022).

Icey
Community Support
Community Support

Hi @Anonymous ,

 

Create two columns and use the previous measure like below:

Icey_0-1645421415523.png

WeekNum = 
"W " & FORMAT ( [Week], "0#" )
Quarter Label = 
[Year] & " Q"
    & QUARTER ( [Date] )

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

This is exactly what I was looking, the only thing is that I'm not interested in seeing the accumulation from the previous year. I am only interested in the movements occuring from january and on, but the cutting of the y axis is the applications from the previous year

Icey
Community Support
Community Support

Hi @Anonymous ,

 

How about this?

Measure 2 =
VAR CurrentWeek_ =
    MAX ( 'Date'[StartDate_Week] )
VAR StartDate_Year =
    CALCULATE (
        MIN ( 'Date'[StartDate_Week] ),
        FILTER ( ALLSELECTED ( 'Date' ), 'Date'[Year] = MAX ( 'Date'[Year] ) )
    )
RETURN
    CALCULATE (
        COUNTROWS ( 'Table' ),
        'Table'[Date of Application ] <= CurrentWeek_,
        'Table'[Date of Application ] >= StartDate_Year
    )

Icey_1-1645494536044.png

 

Or this?

Measure 3 = 
VAR CurrentWeek_ =
    MAX ( 'Date'[StartDate_Week] )
VAR CurrentYear_ =
    MAX ( 'Date'[Year] )
RETURN
    CALCULATE (
        COUNTROWS ( 'Table' ),
        'Table'[Date of Application ] <= CurrentWeek_,
        YEAR ( 'Table'[Date of Application ] ) = CurrentYear_
    )

Icey_0-1645494517055.png

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks alot! This was really helpful, and have pointed me in the right direction.

Anonymous
Not applicable

Hi @Daryl-Lynch-Bzy

 

Of couse, here are some sample data

 

Education Date of Application Start upWeek Type
321-12-202130-03-2022 52Application
201-02-202230-03-2022  6Application
301-01-202230-03-2022    1Application
131-01-202230-03-2022    6Application
210-10-202130-03-2022   42Application
207-02-202230-03-2022   7Application
325-01-202230-03-2022   5Application

 

And I would like to map the accumulation of applications, as each week passes througout 2022; y-axis: number of received applications and x-axis: week nr..

To make matters more complicated I'm interested in week zero (x=0), having y= to the number of applications, received in 2021, for educations staring in 2022.

 

Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @Anonymous - could you share some sample data in a table showing example of what you mean by SUM and COUNTROWS?

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.