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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

problem with dax code in a measure

Hello champs,

 

I have following measure but it doesn't show me values(empty cells), it doesnt say error either. When I remove  (SelectedYear - TopEventYear) > 5 at the bottom , all works correctly , it shows the total, thats fine but I don't need total what I need to achieve extra condition "greater than 5 years from total" . Any idea how to achieve it? In Months would be great as well. which is 60. I tried many ways and now I'm lack of ideas.

Measure:

 

pokus6 =
VAR SelectedYear = SELECTEDVALUE('Calendar'[Date].[Year])  
RETURN  
    COUNTROWS(
        FILTER(
            CecCaseDetail,
            VAR TopFromStateID =
                CALCULATE(
                    SELECTEDVALUE(CecCaseEvent[FromStateOfProceedingID]),
                    TOPN(
                        1,
                        FILTER(
                            ALL(CecCaseEvent),
                            CecCaseEvent[CecCaseID] = CecCaseDetail[CecCaseId] &&
                            CecCaseEvent[ToStateOfProceedingID] <> CecCaseEvent[FromStateOfProceedingID] &&
                            YEAR(CecCaseEvent[EventDate]) = SelectedYear
                        ),
                        CecCaseEvent[EventOrder],
                        DESC
                    )
                )
            VAR TopEventDate =
                CALCULATE(
                    MAX(CecCaseEvent[EventDate]),
                    CecCaseEvent[FromStateOfProceedingID] = 4
                )
            VAR TopEventYear = YEAR(TopEventDate)
            RETURN
                TopFromStateID IN {4} &&
                NOT(ISBLANK(TopEventYear)) &&
                (SelectedYear - TopEventYear) > 5 &&
                CALCULATE(
                    COUNT(CecCaseDetail[CecCaseId]),
                    CecCaseEvent[EventID] = 64,
                    YEAR(CecCaseEvent[EventDate]) = SelectedYear,
                    CecCaseEvent[CecCaseId] = CecCaseEvent[CecCaseId]
                ) && IF(ISBLANK(TopFromStateID), 0, TopFromStateID) &&
                COUNTROWS(
                    FILTER(
                        'CecLeadingCase',
                        'CecLeadingCase'[CecCaseId] = CecCaseDetail[CecCaseId]
                    )
                )
        )
    )
 
HERE is picture I tried to explain how it works , we need to achieve "the green arrow " greater more than 5 years from the red rectangle. Forgot to write in the picture the Event Date column is CecCaseEvent[EventDate].
 
 poko_0-1740579019296.png

 

2 REPLIES 2
rajendraongole1
Super User
Super User

Hi @Anonymous  - Add a debug measure to check TopEventYear and SelectedYear separately to confirm they are correctly calculated.

 

DebugMeasure =
VAR SelectedYear = SELECTEDVALUE('Calendar'[Date].[Year])
VAR TopEventDate =
CALCULATE(
MAX(CecCaseEvent[EventDate]),
CecCaseEvent[FromStateOfProceedingID] = 4
)
VAR TopEventYear = YEAR(TopEventDate)
RETURN
"Selected Year: " & SELECTEDVALUE('Calendar'[Date].[Year]) &
" | Top Event Year: " & IF(ISBLANK(TopEventYear), "Blank", FORMAT(TopEventYear, "0")) &
" | Difference: " & IF(ISBLANK(TopEventYear), "N/A", FORMAT(SelectedYear - TopEventYear, "0"))

 

Modify your measure to handle cases where TopEventYear is blank.

pokus6 =
VAR SelectedYear = SELECTEDVALUE('Calendar'[Date].[Year])
VAR TopEventDate =
CALCULATE(
MAX(CecCaseEvent[EventDate]),
CecCaseEvent[FromStateOfProceedingID] = 4
)
VAR TopEventYear = YEAR(TopEventDate)
VAR YearDifference = IF(ISBLANK(TopEventYear), 0, SelectedYear - TopEventYear)
RETURN
COUNTROWS(
FILTER(
CecCaseDetail,
VAR TopFromStateID =
CALCULATE(
SELECTEDVALUE(CecCaseEvent[FromStateOfProceedingID]),
TOPN(
1,
FILTER(
ALL(CecCaseEvent),
CecCaseEvent[CecCaseID] = CecCaseDetail[CecCaseId] &&
CecCaseEvent[ToStateOfProceedingID] <> CecCaseEvent[FromStateOfProceedingID] &&
YEAR(CecCaseEvent[EventDate]) = SelectedYear
),
CecCaseEvent[EventOrder],
DESC
)
)
RETURN
TopFromStateID IN {4} &&
NOT(ISBLANK(TopEventYear)) &&
YearDifference > 5 &&
CALCULATE(
COUNT(CecCaseDetail[CecCaseId]),
CecCaseEvent[EventID] = 64,
YEAR(CecCaseEvent[EventDate]) = SelectedYear,
CecCaseEvent[CecCaseId] = CecCaseEvent[CecCaseId]
) &&
COUNTROWS(
FILTER(
'CecLeadingCase',
'CecLeadingCase'[CecCaseId] = CecCaseDetail[CecCaseId]
)
)
)
)

 

Instead of checking if the difference is greater than 5 years, check if it's greater than 60 months.

Replace (SelectedYear - TopEventYear) > 5 with MonthDifference > 60. check this.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Anonymous
Not applicable

sorry Iam lost now how to implement debug measure. Can you tell me what to do with the debug measure. I tried to fit in but it cause empty cell again

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors