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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
nick9one1
Helper III
Helper III

Strange behaviour using metric vs hard coded value

I have a table that lists bookings by location, academic year, financial year, financial week. 

 

I'm trying to count the number of rows for the lastest financial week and year entry.

 

 

Booked Rooms 4 = CALCULATE (
    COUNTX ( 'Lettings FACT_LettingsWeekly', 'Lettings FACT_LettingsWeekly'[LettingsFactKey] )
    ,FILTER ( 'Lettings DIM_ReservationType', 'Lettings DIM_ReservationType'[ReservationTypeKey] = 1 )
    ,FILTER ( 'Lettings FACT_LettingsWeekly', 'Lettings FACT_LettingsWeekly'[FinancialWeek] = [Max Week])
    ,FILTER ( 'Lettings FACT_LettingsWeekly', 'Lettings FACT_LettingsWeekly'[FinancialYear] = [Max Year])
    )
Max Week = MAX('Lettings FACT_LettingsWeekly'[FinancialWeek])
Max Year = MAX('Lettings FACT_LettingsWeekly'[FinancialYear])

 

 
you can see here that the total is 374, which is incorrect. It should be 163

nick9one1_0-1682084237954.png


When I change the measure to use '33' for week number instead of [Max Week] it's correct. 

 

nick9one1_1-1682084442300.png

 

 

why is this?

 

Thanks!

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

@nick9one1 

I think you are getting caught by the measures [Max Week] and [Max Year] getting calculated in the context of theCOUNTX iteration.  Try it like this, where the value is set outside the iteration and used inside it.  Does that help?

 

 

 

Booked Rooms 4 = 
VAR _MaxWeek = [Max Week]
VAR _MaxYear = [Max Year]
RETURN
CALCULATE (
    COUNTX ( 'Lettings FACT_LettingsWeekly', 'Lettings FACT_LettingsWeekly'[LettingsFactKey] )
    ,FILTER ( 'Lettings DIM_ReservationType', 'Lettings DIM_ReservationType'[ReservationTypeKey] = 1 )
    ,FILTER ( 'Lettings FACT_LettingsWeekly', 'Lettings FACT_LettingsWeekly'[FinancialWeek] = _MaxWeek)
    ,FILTER ( 'Lettings FACT_LettingsWeekly', 'Lettings FACT_LettingsWeekly'[FinancialYear] = _MaxYear)
    )

 

 

 

View solution in original post

2 REPLIES 2
nick9one1
Helper III
Helper III

Thats done it 🙂 thank you!

jdbuchanan71
Super User
Super User

@nick9one1 

I think you are getting caught by the measures [Max Week] and [Max Year] getting calculated in the context of theCOUNTX iteration.  Try it like this, where the value is set outside the iteration and used inside it.  Does that help?

 

 

 

Booked Rooms 4 = 
VAR _MaxWeek = [Max Week]
VAR _MaxYear = [Max Year]
RETURN
CALCULATE (
    COUNTX ( 'Lettings FACT_LettingsWeekly', 'Lettings FACT_LettingsWeekly'[LettingsFactKey] )
    ,FILTER ( 'Lettings DIM_ReservationType', 'Lettings DIM_ReservationType'[ReservationTypeKey] = 1 )
    ,FILTER ( 'Lettings FACT_LettingsWeekly', 'Lettings FACT_LettingsWeekly'[FinancialWeek] = _MaxWeek)
    ,FILTER ( 'Lettings FACT_LettingsWeekly', 'Lettings FACT_LettingsWeekly'[FinancialYear] = _MaxYear)
    )

 

 

 

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! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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