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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
julsr
Resolver III
Resolver III

Getting value for previous days on a specific day doesn't return data even if there's data

Hello everyone,

 

I have a formula that looks for the previous days (for example if today is Tuesday, it'll return as a result the previous 6 Mondays). It was working without problem but now when I filter for yesterday (04/11/2024), it returns null for all the previous Mondays even if I have data in my database (apparently is only happening with yesterday). Does anyone know what's wrong?

julsr_0-1730838715218.png

This is the code:

[Measure_Name] =
VAR CurrentDate = MAX(Table_Name[Date_Column])
-- Calculate dates for the previous same weekdays
VAR Previous1 = CurrentDate - 7
VAR Previous2 = CurrentDate - 14
VAR Previous3 = CurrentDate - 21
VAR Previous4 = CurrentDate - 28
VAR Previous5 = CurrentDate - 35
VAR Previous6 = CurrentDate - 42
-- Summarize and sum the values for the previous same weekdays
VAR Summed1 =
CALCULATE(
[Base_Measure],
Table_Name[Date_Column] = Previous1
)
VAR Summed2 =
CALCULATE(
[Base_Measure],
Table_Name[Date_Column] = Previous2
)
VAR Summed3 =
CALCULATE(
[Base_Measure],
Table_Name[Date_Column] = Previous3
)
VAR Summed4 =
CALCULATE(
[Base_Measure],
Table_Name[Date_Column] = Previous4
)
VAR Summed5 =
CALCULATE(
[Base_Measure],
Table_Name[Date_Column] = Previous5
)
VAR Summed6 =
CALCULATE(
[Base_Measure],
Table_Name[Date_Column] = Previous6
)
RETURN
"Dates: " &
FORMAT(Previous1, "mm/dd/yyyy") & " (" & FORMAT(Summed1, "#,##0.00") & "), " &
FORMAT(Previous2, "mm/dd/yyyy") & " (" & FORMAT(Summed2, "#,##0.00") & "), " &
FORMAT(Previous3, "mm/dd/yyyy") & " (" & FORMAT(Summed3, "#,##0.00") & "), " &
FORMAT(Previous4, "mm/dd/yyyy") & " (" & FORMAT(Summed4, "#,##0.00") & "), " &
FORMAT(Previous5, "mm/dd/yyyy") & " (" & FORMAT(Summed5, "#,##0.00") & "), " &
FORMAT(Previous6, "mm/dd/yyyy") & " (" & FORMAT(Summed6, "#,##0.00") & ")"

 

Thank you everyone!

1 ACCEPTED SOLUTION

Thanks for your help! 

I've found the error. It was related to the time change and how it was stored in the database. You can see that the time is attached to the date. I modified the formula to ensure we are not considering the time on it, and it worked!

julsr_0-1730918315549.png

 

 

[Measure_Name] =
VAR CurrentDate = DATE(YEAR(MAX(Table_Name[Date_Column])),
MONTH(MAX(Table_Name[Date_Column])),
DAY(MAX(Table_Name[Date_Column])))
-- Calculate dates for the previous same weekdays
VAR Previous1 = DATE(YEAR(CurrentDate - 7),
MONTH(CurrentDate - 7),
DAY(CurrentDate - 7))
VAR Previous2 = DATE(YEAR(CurrentDate - 14),
MONTH(CurrentDate - 14),
DAY(CurrentDate - 14))
-- Summarize and sum the values for the previous same weekdays
VAR Summed1 =
CALCULATE(
SUM([Value_Measure]),
FILTER(
ALL(Table_Name),
DATE(YEAR(Table_Name[Date_Column]),
MONTH(Table_Name[Date_Column]),
DAY(Table_Name[Date_Column])) = Previous1
)
)
VAR Summed2 =
CALCULATE(
SUM([Value_Measure]),
FILTER(
ALL(Table_Name),
DATE(YEAR(Table_Name[Date_Column]),
MONTH(Table_Name[Date_Column]),
DAY(Table_Name[Date_Column])) = Previous2
)
)
-- Calculate total and average
VAR Total = Summed1 + Summed2
RETURN
Total/2

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @julsr ,

 

Without knowing the exact content of [Base_Measure] in your expression, it's hard to tell exactly where the error is occurring.

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

 

Best Regards,

Clara Gong

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

 

Hi! Thanks for your reply. The [base_measure] is just a sum with filters that is working for all the other days (except 04/11/2024), this is the unique day where the problem is showing (at least known). I have data available for yesterday (04/11/2024) and for the previous 6 Mondays but as you can see in the first image, it looks like there's no data in there.

 

BASE_MEASURE =
CALCULATE(
    SUM(TABLE_NAME[BASE]),
    FILTER(
        TABLE_NAME,
        TABLE_NAME[CODE] = "A01" ||
        TABLE_NAME[CODE]="A03")
)
Anonymous
Not applicable

Hi @julsr ,

 

As per your description, I created some sample data and put in the two measures you provided. when I select Nov 4 in the slicer, it returns the results correctly.

vkaiyuemsft_0-1730876431643.png

vkaiyuemsft_2-1730876462893.png

 

So, please check your raw data if these dates match the filter TABLE_NAME[CODE] = “A01” | | TABLE_NAME[CODE] = “A03” and if not, it will return blank.

 

If the problem persists, you can also check the differences between these sample data and yours, adding more details so we can better help you solve the problem.

 

 

Best Regards,

Clara Gong

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

Thanks for your help! 

I've found the error. It was related to the time change and how it was stored in the database. You can see that the time is attached to the date. I modified the formula to ensure we are not considering the time on it, and it worked!

julsr_0-1730918315549.png

 

 

[Measure_Name] =
VAR CurrentDate = DATE(YEAR(MAX(Table_Name[Date_Column])),
MONTH(MAX(Table_Name[Date_Column])),
DAY(MAX(Table_Name[Date_Column])))
-- Calculate dates for the previous same weekdays
VAR Previous1 = DATE(YEAR(CurrentDate - 7),
MONTH(CurrentDate - 7),
DAY(CurrentDate - 7))
VAR Previous2 = DATE(YEAR(CurrentDate - 14),
MONTH(CurrentDate - 14),
DAY(CurrentDate - 14))
-- Summarize and sum the values for the previous same weekdays
VAR Summed1 =
CALCULATE(
SUM([Value_Measure]),
FILTER(
ALL(Table_Name),
DATE(YEAR(Table_Name[Date_Column]),
MONTH(Table_Name[Date_Column]),
DAY(Table_Name[Date_Column])) = Previous1
)
)
VAR Summed2 =
CALCULATE(
SUM([Value_Measure]),
FILTER(
ALL(Table_Name),
DATE(YEAR(Table_Name[Date_Column]),
MONTH(Table_Name[Date_Column]),
DAY(Table_Name[Date_Column])) = Previous2
)
)
-- Calculate total and average
VAR Total = Summed1 + Summed2
RETURN
Total/2

ajohnso2
Super User
Super User

Try this

[Measure_Name] =
VAR CurrentDate = MAX(Table_Name[Date_Column])
-- Calculate dates for the previous same weekdays
VAR Previous1 = CurrentDate - 7
VAR Previous2 = CurrentDate - 14
VAR Previous3 = CurrentDate - 21
VAR Previous4 = CurrentDate - 28
VAR Previous5 = CurrentDate - 35
VAR Previous6 = CurrentDate - 42
-- Summarize and sum the values for the previous same weekdays
VAR Summed1 =
CALCULATE(
[Base_Measure],
ALL(Table_Name[Date_Column]) = Previous1
)
VAR Summed2 =
CALCULATE(
[Base_Measure],
ALL(Table_Name[Date_Column]) = Previous2
)
VAR Summed3 =
CALCULATE(
[Base_Measure],
ALL(Table_Name[Date_Column]) = Previous3
)
VAR Summed4 =
CALCULATE(
[Base_Measure],
ALL(Table_Name[Date_Column]) = Previous4
)
VAR Summed5 =
CALCULATE(
[Base_Measure],
ALL(Table_Name[Date_Column]) = Previous5
)
VAR Summed6 =
CALCULATE(
[Base_Measure],
ALL(Table_Name[Date_Column]) = Previous6
)
RETURN
"Dates: " &
FORMAT(Previous1, "mm/dd/yyyy") & " (" & FORMAT(Summed1, "#,##0.00") & "), " &
FORMAT(Previous2, "mm/dd/yyyy") & " (" & FORMAT(Summed2, "#,##0.00") & "), " &
FORMAT(Previous3, "mm/dd/yyyy") & " (" & FORMAT(Summed3, "#,##0.00") & "), " &
FORMAT(Previous4, "mm/dd/yyyy") & " (" & FORMAT(Summed4, "#,##0.00") & "), " &
FORMAT(Previous5, "mm/dd/yyyy") & " (" & FORMAT(Summed5, "#,##0.00") & "), " &
FORMAT(Previous6, "mm/dd/yyyy") & " (" & FORMAT(Summed6, "#,##0.00") & ")"

Thanks for your reply, I got this result

julsr_1-1730840017461.png

I did it like this that is the right way to use the ALL but still didn't work

ALL(Table_Name,Table_Name[Date_Column]) = Previous1

julsr_2-1730840187207.png

 

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.

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