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

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

Reply
govi
Helper II
Helper II

Count last occurrence, criteria in multiple rows

Hi,

I have this table:

 

2020-04-29_130913.png

In column "newUser" I return a "1" when the column "status" says "SubscriptionCreated"

In column "excludedUser" I return a "1" when the column "status" says "ExcludedFromProject"

But sometimes a user is accidentally excluded, and later included ("IncludedInProject") again.

 

In the example above (rows in yellow) the first "ExcludedFromProject" for user 14195 must not return "1" in column "excludedUser"

because is included again, on 9-1-2019 the user is excluded for real, and then "1" should be returned.

 

Put simple: if "ExcludedFromProject" occurs more than once for a user, "1" must returned at the last occurence of "ExcludedFromProject".

 

Can someone help?

Thank you!

govi

1 ACCEPTED SOLUTION

Hi @govi ,

 

If you want calculated columns, you can do like this:

Column = 
IF(
    Sheet1[status] = "SC",
    1, BLANK()
)
Column 2 = 
VAR x = 
CALCULATE(
    MAX(Sheet1[timestamp]),
    FILTER(
        ALL(Sheet1),
        Sheet1[userId] = EARLIER(Sheet1[userId]) && Sheet1[status] = "EFP"
    )
)
VAR y = 
CALCULATE(
    MIN(Sheet1[timestamp]),
        FILTER(
            ALL(Sheet1),
            Sheet1[userId] = EARLIER(Sheet1[userId]) && Sheet1[status] = "EFP"
        )
)
VAR z = 
SWITCH(
    TRUE(),
    Sheet1[timestamp] = x && Sheet1[status] = "EFP", "1",
    Sheet1[timestamp] >= y && Sheet1[timestamp] <= x &&Sheet1[status] = "EFP", "no value",
    BLANK()
)
RETURN
z

x1.PNG

 

Best regards,
Lionel Chen

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

4 REPLIES 4
v-lionel-msft
Community Support
Community Support

Hi @govi ,

 

Try the measures:

newUser = 
IF(
    MAX(Sheet1[status]) = "SC",
    1,
    BLANK()
)
excludedUser = 
VAR x = 
CALCULATE(
    MAX(Sheet1[timestamp]),
    FILTER(
        ALL(Sheet1),
        Sheet1[userId] = SELECTEDVALUE(Sheet1[userId]) && Sheet1[status] = "EFP"
    )
)
VAR y = 
CALCULATE(
    MIN(Sheet1[timestamp]),
        FILTER(
            ALL(Sheet1),
            Sheet1[userId] = SELECTEDVALUE(Sheet1[userId]) && Sheet1[status] = "EFP"
        )
)
VAR z = 
SWITCH(
    TRUE(),
    SELECTEDVALUE(Sheet1[timestamp]) = x && SELECTEDVALUE(Sheet1[status]) = "EFP", "1",
    SELECTEDVALUE(Sheet1[timestamp]) >= y && SELECTEDVALUE(Sheet1[timestamp]) <= x && SELECTEDVALUE(Sheet1[status]) = "EFP", "no value",
    BLANK()
)
RETURN
z

c6.PNG

 

Best regards,
Lionel Chen

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

Hi @v-lionel-msft ,

 

Thanks for your solution!

However I encounter a problem:

I would like to create a column with the "excludedUser" directly in my table.

I tried to put your DAX in a new column but that didn't work out.

 

Could you help me again?

 

Thanks!

Govi

Hi @govi ,

 

If you want calculated columns, you can do like this:

Column = 
IF(
    Sheet1[status] = "SC",
    1, BLANK()
)
Column 2 = 
VAR x = 
CALCULATE(
    MAX(Sheet1[timestamp]),
    FILTER(
        ALL(Sheet1),
        Sheet1[userId] = EARLIER(Sheet1[userId]) && Sheet1[status] = "EFP"
    )
)
VAR y = 
CALCULATE(
    MIN(Sheet1[timestamp]),
        FILTER(
            ALL(Sheet1),
            Sheet1[userId] = EARLIER(Sheet1[userId]) && Sheet1[status] = "EFP"
        )
)
VAR z = 
SWITCH(
    TRUE(),
    Sheet1[timestamp] = x && Sheet1[status] = "EFP", "1",
    Sheet1[timestamp] >= y && Sheet1[timestamp] <= x &&Sheet1[status] = "EFP", "no value",
    BLANK()
)
RETURN
z

x1.PNG

 

Best regards,
Lionel Chen

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

Brilliant @v-lionel-msft !

 

Thanks you!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.