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

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

Reply
Zbig62
Regular Visitor

Value 7 days earlier than selected

Hello everyone

Please help

I want to get information about the number of measurements (count of result) 7 days earlier than the selected day

The table with sample data looks like this:

Zbig62_0-1727377651268.png

For example, I select the day: 2024-02-01 where there were 16 measurements and I need to create a measure showing how many measurements there were 7 days earlier

 

Zbig62_1-1727377691796.png

The measure I wrote gives a "Blank" result every time. Where is the error?

 

DAY - 7 =

var a = SELECTEDVALUE('public Measurement'[DAY])

RETURN

CALCULATE(

COUNT('public Measurement'[result]); FILTER('public Measurement'; 'public  Measurement'[DAY] = a - 7

              )

        )

4 ACCEPTED SOLUTIONS

You have to change the filter in your expression

DAY - 7 =

CALCULATE (
    COUNT ( 'public Measurement'[result] ),
    FILTER (
        'public Measurement',
        'public  Measurement'[DAY]
            = DATEADD ( SELECTEDVALUE ( 'public Measurement'[DAY] ), -7, DAY )
    )
)


Regards,
Sachin
Check out my Blog

View solution in original post

I have a problem with the type of parameters in and I don't know how to deal with it

Zbig62_0-1727413571956.png

 

View solution in original post

Anonymous
Not applicable

Hi @Zbig62 

 

I don't think you should use the “DAY” field in the "public Measurement" table as a slicer, please create a calendar table to use as a slicer. And don't create a relationship between the calendar table and the "public Measurement" table.

1. Create a calendar table and use it as a slicer.

 

Calendar = DISTINCT('public Measurement'[DAY])

 

 2. Replace the field “DAY” in your measure with the field “DAY” of calendar table.

 

DAY - 7 = 
CALCULATE(
    COUNT('public Measurement'[result]),
    FILTER(
        'public Measurement',
        'public Measurement'[DAY] = SELECTEDVALUE('Calendar'[DAY]) - 7
    )
)

 

 

Here is my simple test result:

vxianjtanmsft_0-1727427417068.png

By the way, when the day DAY-7 does not exist for the "DAY" in your data, the measure will return blank. For example, if you slicer selects 2024-02-01, DAY-7 is 2024-1-25, because the data for 2024-1-25 does not exist in your table, the measure returns blank.

 

Best Regards,
Jarvis Tang
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

Sorry I didnt realise that Dateadd function needs an exclusive date table.Your approach wouldnt work as you are trying to compare rows within the current row context and subtracting from the same value using a filter.

As suggested by @Anonymous you need a date table. You can use the solution provided by @Anonymous 



Regards,
Sachin
Check out my Blog

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @Zbig62 

 

I don't think you should use the “DAY” field in the "public Measurement" table as a slicer, please create a calendar table to use as a slicer. And don't create a relationship between the calendar table and the "public Measurement" table.

1. Create a calendar table and use it as a slicer.

 

Calendar = DISTINCT('public Measurement'[DAY])

 

 2. Replace the field “DAY” in your measure with the field “DAY” of calendar table.

 

DAY - 7 = 
CALCULATE(
    COUNT('public Measurement'[result]),
    FILTER(
        'public Measurement',
        'public Measurement'[DAY] = SELECTEDVALUE('Calendar'[DAY]) - 7
    )
)

 

 

Here is my simple test result:

vxianjtanmsft_0-1727427417068.png

By the way, when the day DAY-7 does not exist for the "DAY" in your data, the measure will return blank. For example, if you slicer selects 2024-02-01, DAY-7 is 2024-1-25, because the data for 2024-1-25 does not exist in your table, the measure returns blank.

 

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

 

Zbig62
Regular Visitor

Hello
Thank you for your quick response. I have a small problem with this function. If I use it in a variable definition
I get the message SYNTAX ERROR

day - 7 =

a = DATEADD(SELECTEDVALUE('public Measurement'[DAY]),-7,day)

Return

CALCULATE(

COUNT('public Measurement'[result]); FILTER('public Measurement'; 'public  Measurement'[DAY] = a 

              )

        )

You have to change the filter in your expression

DAY - 7 =

CALCULATE (
    COUNT ( 'public Measurement'[result] ),
    FILTER (
        'public Measurement',
        'public  Measurement'[DAY]
            = DATEADD ( SELECTEDVALUE ( 'public Measurement'[DAY] ), -7, DAY )
    )
)


Regards,
Sachin
Check out my Blog

I have a problem with the type of parameters in and I don't know how to deal with it

Zbig62_0-1727413571956.png

 

I tried another approach and I also get a message about parameter type mismatch

Zbig62_1-1727418875897.png

 

 

Sorry I didnt realise that Dateadd function needs an exclusive date table.Your approach wouldnt work as you are trying to compare rows within the current row context and subtracting from the same value using a filter.

As suggested by @Anonymous you need a date table. You can use the solution provided by @Anonymous 



Regards,
Sachin
Check out my Blog
SachinNandanwar
Super User
Super User

DATEADD(SELECTEDVALUE('public Measurement'[DAY]),-7,day)



Regards,
Sachin
Check out my Blog

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.