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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
MrMichael
Frequent Visitor

Remove Variable filter context

Hi, 

 

I am calculating earned premium up till a specific date using the variable "LatestReportingDate".
However, when using this variable, the filter context "YOA <= 2020" is kept. 

Earned = 

VAR LatestReportingDate = 

CALCULATE(MAX(TABLE[ReportingPeriodStartDate]),
FILTER(TABLE, TABLE[YOA] <= 2020))

RETURN CALCULATE(SUM(TABLE[EarnedPremium]),
FILTER(TABLE, TABLE[ReportingPeriodStartDate] = LatestReportingDate)
)

When visualizing 

Class12
YOAEarned Earned
2019xxxxxx
2020xxxxxx
2021BLANKBLANK
2022BLANKBLANK


It seems the filter context from LatestReportingPeriod spills over such that earned is not calculated for 2021 and 2022 YOA. 
I have tried using ALL, ALLEXCEPT to no avail. This also removes connections in the model, which I do not want. 

 

1 ACCEPTED SOLUTION
tamerj1
Community Champion
Community Champion

Hi @MrMichael 
The LatestReportingDate will return the last available date in in current filter context only if the year is 2020 or less. In the case of the year 2021 it will return blank. In this case the measure will also return blank as there is no blank date in your table. 
You can FILTER ( ALL ( Table ), ..... in both measures but the best way to achieve what you need is the have a date table.

View solution in original post

4 REPLIES 4
tamerj1
Community Champion
Community Champion

Hi @MrMichael 
The LatestReportingDate will return the last available date in in current filter context only if the year is 2020 or less. In the case of the year 2021 it will return blank. In this case the measure will also return blank as there is no blank date in your table. 
You can FILTER ( ALL ( Table ), ..... in both measures but the best way to achieve what you need is the have a date table.

Thank you. 
However, I find that using ALL on both measures, removes connections in my model which makes earned premium the same for all years. 

@MrMichael 
This is why I advised you to use a date table. This will give you the freedom to filter without the need for sophisticated dax code.

SpartaBI
Community Champion
Community Champion

@MrMichael try this:

 

Earned =
VAR LatestReportingDate =
    CALCULATE (
        MAX ( TABLE[ReportingPeriodStartDate] ),
        TABLE[YOA] <= 2020
    )
RETURN
    CALCULATE (
        SUM ( TABLE[EarnedPremium] ),
        TABLE[ReportingPeriodStartDate] = LatestReportingDate
    )

 




2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.