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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
justinmpalmer
Frequent Visitor

Calculating totals to date with caveat of limiting canceled records

date_canceled  Return
1/10/2018  1/26/2018
1/22/2018  1/26/2018
1/26/2018  1/29/2018
1/26/2018  2/26/2019
1/29/2018  3/26/2019
9/10/2019  2/22/2020
1/22/2019  3/26/2020
2/26/2019  4/26/2020
3/26/2019   
10/10/2020   
2/22/2020   
3/26/2020   
4/26/2020   

 

I have a set of dates date_canceled and I want to get all of the records for today 1/26/2021 that have not been cancelled, but I want it to look over every year and use the month and day for each year. You can see the results I am looking for.

 

I am looking to count how many records that are returned on a week by week basis. Tracking applications that have not cancelled to this date and for each year.

 

I really don't even know where to begin.

 

--------------------------------------------

Update with more detail. Sorry it was late for me and I was not up to the task.

 

With the table "Applications" and the following information (Note: Filter Out? is not part of the table, but rather the records that need removed to have the correct result.

 

idSales WeekSales Season Start DateApplication Received DateDate CancelledProgram Start DateFilter Out?
256977129/1/201711/22/20171/10/20188/31/2018Yes
263896209/1/20171/18/20181/22/20188/31/2018Yes
262824189/1/20171/5/20181/26/20188/31/2018No
259859199/1/20171/8/2018 8/31/2018No
24289799/1/201711/3/20171/29/20188/31/2018No
29070209/1/20187/19/20181/24/20198/31/2019Yes
29524919/1/20189/5/20181/5/20198/31/2019Yes
26267309/1/20181/5/20182/1/20198/31/2019No
315053229/1/20181/30/20192/13/20198/31/2019No
303811119/1/201811/16/2018 8/31/2019No
352911119/1/201911/19/20199/2/20208/31/2020Yes
362368199/1/20191/17/20209/9/20208/31/2020Yes
357165159/1/201912/19/20192/10/20208/31/2020No
358855189/1/20191/7/20209/11/20208/31/2020Yes

 

Expected result:

idWeeks to StartSales Season Start DateApplication Received DateDate CancelledProgram Start DateFilter Out?
262824189/1/20171/5/20181/26/20188/31/2018No
259859199/1/20171/8/2018   8/31/2018No
24289799/1/201711/3/20171/29/20188/31/2018No
26267309/1/20181/5/20182/1/20198/31/2019No
315053229/1/20181/30/20192/13/20198/31/2019No
303811119/1/201811/16/2018                                                                                                                                                                   8/31/2019No

 

I calculate Sales Week by looking at the sales season and counting the number of weeks to the Program Start Date.  

Sales Week has 3 possibilities, if: 

  

  1. Application Received Date is < Sales Season Start Date  
    1. Sales Week is 0 
  2. Application Received Date is > Sales Season Start Date  
    1. Sales week is 52 
  3. Otherwise  
    1. Sales week is the week that it happen 

We receive applications before and after the sales Sales Season Start Date / Program Start Date. Management does not want numbers below 0 or 52. They are okay with all sales before and after happening on 0 or 52 in those cases. 

  

I add the following column to Applications: 

  

 

 

_Sales Week = SWITCH(TRUE(), 
DATEDIFF(RELATED('Program Dates'[Sales Season Start Date].[Date]),'Applications'[application_received_on_date].[Date], WEEK) < 0, 0,
DATEDIFF(RELATED('Program Dates'[Sales Season Start Date].[Date]),'Applications'[application_received_on_date].[Date], WEEK) > 52, 52,
DATEDIFF(RELATED('Program Dates'[Sales Season Start Date].[Date]),'Applications'[application_received_on_date].[Date], WEEK) 
) 

 

 

 

I have the following Measure to count a running total to track sales on a week by week basis, but it does not filter out cancelled records based on the current date for each year:

 

 

 

Applications Running Total Week Application Received = 
CALCULATE(
    [COUNTROWS(Applications)],
    FILTER(
        ALLSELECTED(Applications[_Sales Week]),
        ISONORAFTER(Applications[_Sales Week], MAX(Applications[_Sales Week]), DESC)
    )
)

 

 

@lbendlin I have updated this with more information, please let me know if this helps or you need more detail.

 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @justinmpalmer ,

 

Please check if this could meet your requirements:

Measure =
VAR ThisMonth =
    MONTH ( TODAY () )
VAR ThisDay =
    DAY ( TODAY () )
VAR CurrentYear =
    YEAR ( MAX ( Applications[Date Cancelled] ) )
VAR Date_Today =
    IF ( CurrentYear <> BLANK (), DATE ( CurrentYear, ThisMonth, ThisDay ) )
VAR Date_0126 =
    IF ( CurrentYear <> BLANK (), DATE ( CurrentYear, 1, 26 ) )
RETURN
    IF (
        MAX ( Applications[Date Cancelled] ) = BLANK ()
            || MAX ( Applications[Date Cancelled] ) >= Date_0126,
        1
    )

 

For test, use "Date_0126" . For today, use "Date_Today" to get the actual result.

application.jpg

In addition, I have one question:

Why did the four marked records not appear in your expected results? Any other rules I ignored?

 

 

 

Best regards

Icey

 

If this post helps, then consider Accepting it as the solution to help other members find it faster.

View solution in original post

18 REPLIES 18
Icey
Community Support
Community Support

Hi @justinmpalmer ,

 

Please check if this could meet your requirements:

Measure =
VAR ThisMonth =
    MONTH ( TODAY () )
VAR ThisDay =
    DAY ( TODAY () )
VAR CurrentYear =
    YEAR ( MAX ( Applications[Date Cancelled] ) )
VAR Date_Today =
    IF ( CurrentYear <> BLANK (), DATE ( CurrentYear, ThisMonth, ThisDay ) )
VAR Date_0126 =
    IF ( CurrentYear <> BLANK (), DATE ( CurrentYear, 1, 26 ) )
RETURN
    IF (
        MAX ( Applications[Date Cancelled] ) = BLANK ()
            || MAX ( Applications[Date Cancelled] ) >= Date_0126,
        1
    )

 

For test, use "Date_0126" . For today, use "Date_Today" to get the actual result.

application.jpg

In addition, I have one question:

Why did the four marked records not appear in your expected results? Any other rules I ignored?

 

 

 

Best regards

Icey

 

If this post helps, then consider Accepting it as the solution to help other members find it faster.

Thank you @Icey,

 

This looks very promising. How can I incoorporate your measure with my existing running total measure?

 

 

Applications Running Total Week Application Received = 
CALCULATE(
    [COUNTROWS(Applications)],
    FILTER(
        ALLSELECTED(Applications[_Sales Week]),
        ISONORAFTER(Applications[_Sales Week], MAX(Applications[_Sales Week]), DESC)
    )
)

 

Your right about the 4. They should be included in the dataset. Thanks for catching this!

 

Hi @justinmpalmer ,

 

Try this:

visualfilter.gif

 

 

Best regards

Icey

 

If this post helps, then consider Accepting it as the solution to help other members find it faster.

lbendlin
Super User
Super User

"for the given year"  is what throws me off. that sounds awfully unfair to the guys in December versus the guys in January. I think your logic is different from that.

If there are students that canceled before 1/26 of the given year we don't want to count them because they were cancelled. This means that we can compare year over year all students that have not cancelled up to 1/26 of each of the given years.

 

Any that cancelled after 1/26 should still count, because for this year we don't know who is going to cancel after 1/26 because it is not here yet.

lbendlin
Super User
Super User

Your Sales Week column definition seems incorrect.  Please check the rules again.

 

lbendlin_0-1611775870244.png

 

Ah, your definition is missing the "plus one year"  part for the second rule.

 

SW = SWITCH(TRUE(),
Applications[Application Received Date]<Applications[Sales Season Start Date],0,
Applications[Application Received Date]>EDATE(Applications[Sales Season Start Date],12),52,
DATEDIFF(Applications[Sales Season Start Date],Applications[Application Received Date],WEEK))
 
or more concisely:
SW = min(max(0,DATEDIFF(Applications[Sales Season Start Date],Applications[Application Received Date],WEEK)),52)
 
Please explain why 256977 is to be filtered out but 242897 not?

256977 - This is filtered out because the date cancelled is before 1/26

242897 - This is left because the date cancelled is after 1/26

 

Trying your Sales Week definition.

does the year matter?  What does "before 1/26"  even mean?

1/26 for the given year.

 

If they cancelled in 2017 then I can't have cancelled applications for that year that are before 1/26/2017, but I should count records that are for 1/26/2017 and after.

 

If they cancelled in 2018 then I can't have cancelled applications for that year that are before 1/26/2018, but I should count records that are for 1/26/2018 and after.

 

And so on.

@lbendlin any additional thoughts here? I appreciate the help if you can provide.

 

smpa01
Super User
Super User

@justinmpalmerwhat is the exact Filter Out? logic

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

This is what I don't know how to do. I have tried to write a Measure that replaced the current current month and day for each Date Canceled date that would allow me to remove the records.

 

There are two problems. I don't think this is a good fix, feels wrong. 2ndly, Power BI does not like it and throws syntax errors.

 

Something like this is what I tried:

 

 

 

Applications Total Not Cancelled As Of Today = 
COUNTX(
    FILTER(
        Applications,
        Applications[date_canceled].[Date] < DATEVALUE(FORMAT(TODAY(), "MM/DD/") & ALL(Applications[date_canceled].[Year])) ||
        ISBLANK(Applications[date_canceled])
    ),
    COUNTROWS(Applications)
)

 

 

@justinmpalmerI am sorry. I am still confused. Whether power bi does it or not, my question is can you please describe based on what logic you want to populate the Filter out column

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

I want all records returned that are of 2 types:

 

  1. Cancelled on or after the current month/day for the given year that the sales was made
  2. Not cancelled

Does that make sense?

@justinmpalmerattached.

https://drive.google.com/file/d/1ZXeWnn2z4FjXW3LfNUWCx45PZfi-1z8i/view?usp=sharing

 

Capture.PNG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Thanks for the pbx, I am not sure what this solves in relation to the rest of my post.

lbendlin
Super User
Super User

"I want to get all of the records" - what records? Returns? Orders?  Please provide more context and more complete sample data. Please indicate the expected outcome.

Updated with more context. Hopefully this will help.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors