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
ThomasWeppler
Impactful Individual
Impactful Individual

I need help to optimize Dax

Hi power BI community
I have a tabel that looks at diffrent states a task can come through todostaehistory
For each row I want to see if the same task todostaehistory [todoid] has been accepted at a later stage.
So my first line look make sure that we only look at the tasks that are offers todostatehistory[stateid] = 13.
So each row where this isn't the case we can just put a blank value.
The problem really come with VAR nextDate
Here each row look thorugh each other row where the stateid = 13 and l
and find the next row on the same task todostatehistory[todoid] made at a later point in time and with a diffrent todostatehistory[stateid].
 
Here is the DAX:

Accepted =
IF (
    todostatehistory[stateid] <> 13,
    BLANK (),
    VAR currentDate = Todostatehistory[date]
    VAR currentState = todostatehistory[stateid]

 

    VAR nextDate =
        SELECTCOLUMNS (
            CALCULATETABLE (
                TOPN ( 1, todostatehistory, Todostatehistory[id] ),
                ALLEXCEPT ( todostatehistory, todostatehistory[todoid] ),
                todostatehistory[stateid] <> currentState,
                Todostatehistory[date] > currentDate
            ),
            "@val", Todostatehistory[date]
        )
    RETURN
        nextDate
)

My problem is that each row looks though each other row to find the right date. This means that the memory required to update my report grows exponential as I get more rows and that is obviously unsustainable.
Does any of your bright folks have an idea to how I can get around this issue?
All help is greatly appreciated.
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@ThomasWeppler , try like

 

new column =
Maxx(filter(todostatehistory, todostatehistory[todoid] = earlier(todostatehistory[todoid] ) && Todostatehistory[date] > earlier(Todostatehistory[date]) ), Todostatehistory[date])

 

Or break into two column
or create a rank first - new columns
rank = Rankx(filter(todostatehistory, todostatehistory[todoid] = earlier(todostatehistory[todoid] )), Todostatehistory[date],,asc,dense)


new column date=
Maxx(filter(todostatehistory, todostatehistory[todoid] = earlier(todostatehistory[todoid] ) && Todostatehistory[rank] > earlier(Todostatehistory[rank])+1 ), Todostatehistory[date])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@ThomasWeppler , try like

 

new column =
Maxx(filter(todostatehistory, todostatehistory[todoid] = earlier(todostatehistory[todoid] ) && Todostatehistory[date] > earlier(Todostatehistory[date]) ), Todostatehistory[date])

 

Or break into two column
or create a rank first - new columns
rank = Rankx(filter(todostatehistory, todostatehistory[todoid] = earlier(todostatehistory[todoid] )), Todostatehistory[date],,asc,dense)


new column date=
Maxx(filter(todostatehistory, todostatehistory[todoid] = earlier(todostatehistory[todoid] ) && Todostatehistory[rank] > earlier(Todostatehistory[rank])+1 ), Todostatehistory[date])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks @amitchandak It worked perfectly. 
You are a Power BI God.

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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