Reply
avatar user
Anonymous
Not applicable
Partially syndicated - Outbound

DAX measure not working

I am working in Tabular Editor 3, and trying to create a measure in DAX which will allow me to show data in a calculation group where according to the Year selected in a filter the table will show data for that year and the previous year, dynamically changing as the filter selection changes.  I have a working measure for the current year, but am unable to work out why it doesn't work when I try to use "Year - 1" within the calculation.

 

I have a measure which works to identify the Year selected in the filter:

YearOfEntrySelected = SELECTEDVALUE(LookupEntryYear[YearOfEntry])

 

The measure I am using works as long as I don't use - 1:

VAR YearSelected = [YearOfEntrySelected]

 

RETURN

IF(

    SELECTEDVALUE( DataCourseApplications[LatestYearOfEntry] ) = YearSelected,

    CALCULATE(

        COUNTROWS( DataCourseApplications )

        , DataCourseApplications[LatestRecord] <> BLANK()

    )

)

 

But does not work when I add the - 1 to the variable (or directly to the Measure and reference that in the IF statement):

VAR YearSelected = [YearOfEntrySelected] - 1

RETURN

IF(

    SELECTEDVALUE( DataCourseApplications[LatestYearOfEntry] ) = YearSelected,

    CALCULATE(

        COUNTROWS( DataCourseApplications )

        , DataCourseApplications[LatestRecord] <> BLANK()

    )

)

 

The Year values all look to be formatted as Whole Numbers, so I don't believe that there should be any issue with the minus 1 and it matching to the LatestYearOfEntry.

 

Any thoughts  and ideas welcome - I've asked a number of colleagues and we are all perplexed!

 

 

1 ACCEPTED SOLUTION
avatar user
Anonymous
Not applicable

Syndicated - Outbound

Hi @Anonymous ,

Please have a try.

To avoid this problem, you can use the MAX or MIN function instead of SELECTEDVALUE, which will return the maximum or minimum value in the filter context. For example, you can use this formula:

VAR YearSelected = MAX(LookupEntryYear[YearOfEntry]) - 1
RETURN
IF(
    MAX(DataCourseApplications[LatestYearOfEntry]) = YearSelected,
    CALCULATE(
        COUNTROWS(DataCourseApplications),
        DataCourseApplications[LatestRecord] <> BLANK()
    )
)

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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
avatar user
Anonymous
Not applicable

Syndicated - Outbound

Hi @Anonymous ,

Please have a try.

To avoid this problem, you can use the MAX or MIN function instead of SELECTEDVALUE, which will return the maximum or minimum value in the filter context. For example, you can use this formula:

VAR YearSelected = MAX(LookupEntryYear[YearOfEntry]) - 1
RETURN
IF(
    MAX(DataCourseApplications[LatestYearOfEntry]) = YearSelected,
    CALCULATE(
        COUNTROWS(DataCourseApplications),
        DataCourseApplications[LatestRecord] <> BLANK()
    )
)

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

 

 

 

lbendlin
Super User
Super User

Syndicated - Outbound

What's the relevance of calculation groups here?  Isn't that something a regular measure can do?

avatar user

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.

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)