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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Jalalmn
Frequent Visitor

Filter in measure does not work properly exceptionally in the last year

Hi

I have created a measure that calculates the income in terms of year to date.
It works properly for all years in my data, but only in the last year the result is not correct. I have digged into my data and understood that it does not take into effect the last few days in the latest month (which is in May 2024). For previous years it the results of absolutely correct. Only in the year 2024 the results are wrong!

Why it works correctly for all years except for 2024?? why it misses the last few days?

GBV = VAR year_in_context = SELECTEDVALUE('Date'[Year])
      VAR month_in_focus = MONTH(TODAY())
      VAR day_in_focus = DAY(TODAY())
      VAR last_day = DATE(year_in_context, month_in_focus, day_in_focus)
      VAR first_day = DATE(year_in_context, 1, 1)
      VAR Result =  CALCULATE(
            SUM('bookings'[Price]),
                FILTER(
                'bookings',
                'bookings'[BookingDate] >= first_day &&
                'bookings'[BookingDate] <= last_day
                ))
    RETURN Result

Many thanks in advance for your help!
1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Jalalmn ,

 

Are you referring to a maximum date of the end of the current month .

You may consider using the following dax:

 

GBV
 = VAR year_in_context = SELECTEDVALUE('Date'[Year])
      VAR month_in_focus = MONTH(TODAY())
      VAR day_in_focus = DAY(TODAY())
      VAR last_day1 = DATE(year_in_context, month_in_focus, day_in_focus)  
      VAR last_day2 = EOMONTH(last_day1 ,0)
      VAR first_day = DATE(year_in_context, 1, 1)
      VAR Result =  CALCULATE(
            SUM('bookings'[Price]),
                FILTER(
                ALL('bookings'),
                'bookings'[BookingDate] >= first_day &&
                'bookings'[BookingDate] <= last_day2
                ))
    RETURN
Result

 

You can check to see if there are filters filtering that are causing the 2024 values to appear incorrectly or to see if the table-to-table relationships are connected correctly.

 

If the results don't meet your expectations, 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,

Liu Yang

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

2 REPLIES 2
Jalalmn
Frequent Visitor

Hi Liu,

 

Late at night I understood where the problem come from 🙂

Actually I need ytd of income, not the income till the end of month. So it depends on the current day.

The problem was happening because my date table had stopped gettin updated to include the last few days into the dates 🙂

 

Many thanks anyway,

Jalal

v-yangliu-msft
Community Support
Community Support

Hi  @Jalalmn ,

 

Are you referring to a maximum date of the end of the current month .

You may consider using the following dax:

 

GBV
 = VAR year_in_context = SELECTEDVALUE('Date'[Year])
      VAR month_in_focus = MONTH(TODAY())
      VAR day_in_focus = DAY(TODAY())
      VAR last_day1 = DATE(year_in_context, month_in_focus, day_in_focus)  
      VAR last_day2 = EOMONTH(last_day1 ,0)
      VAR first_day = DATE(year_in_context, 1, 1)
      VAR Result =  CALCULATE(
            SUM('bookings'[Price]),
                FILTER(
                ALL('bookings'),
                'bookings'[BookingDate] >= first_day &&
                'bookings'[BookingDate] <= last_day2
                ))
    RETURN
Result

 

You can check to see if there are filters filtering that are causing the 2024 values to appear incorrectly or to see if the table-to-table relationships are connected correctly.

 

If the results don't meet your expectations, 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,

Liu Yang

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.