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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

Better way using filter contexts

Hi,

 

I have a very simple data set which looks like the following:

 

PID          MID         Date

1128/02/2019
128/04/2019
1320/04/2019
1428/05/2019
2128/02/2019
2226/04/2019
2322/06/2019
241/07/2019
251/10/2019

 

PID represents a project, MID represents a milestone and Date represents when it was achieved.

 

I am trying to write a simple measure to get the most recent milestone for the project in the current filter context.

 

I have wrote the following which works however it feels list a very poor, inneffecient approach.  Is there a combination with ALLEXCEPT or something along those lines which will perform the same action?

 

M = 
VAR x = SELECTEDVALUE(Milestones[PID])

RETURN
CALCULATE(
    MAX(Milestones[Date]),
    FILTER(
        ALL(Milestones),
        Milestones[PID] = x
    )
)

 

PIDMIDDateM
1128/02/201928/05/2019
128/04/201928/05/2019
1320/04/201928/05/2019
1428/05/201928/05/2019
2128/02/20191/10/2019
2226/04/20191/10/2019
2322/06/20191/10/2019
241/07/20191/10/2019
251/10/20191/10/2019

 

 

1 ACCEPTED SOLUTION

@Anonymous ,

 

Instead, you may add a calculated column.

Column =
RELATED ( Projects[P_name] )
Community Support Team _ Sam Zha
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-chuncz-msft
Community Support
Community Support

@Anonymous ,

 

You may refer to the measure below.

Measure =
CALCULATE (
    MAX ( Milestones[Date] ),
    ALLEXCEPT ( Milestones, Milestones[PID] )
)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

thanks @v-chuncz-msft .

 

If I add in another table named Projects which looks as follows and join them off PID can I still use an ALLEXCEPT to achieve the desired result if I replace Milestones[PID] with Projects[P_name]?

 

[Projects]

PIDP_name
1Proj A
2Proj B

 

 

New desired result

P_name

MIDDateM
Proj A128/02/201928/05/2019
Proj A28/04/201928/05/2019
Proj A320/04/201928/05/2019
Proj A428/05/201928/05/2019
Proj B128/02/20191/10/2019
Proj B226/04/20191/10/2019
Proj B322/06/20191/10/2019
Proj B41/07/20191/10/2019
Proj B51/10/20191/10/2019

 

 

I understand that now the Milestones[PID] isn't there to add filter context but if I try and replace it with Projects[P_name] I get some really weird cross join results.

 

Thanks 

Ben

@Anonymous ,

 

Instead, you may add a calculated column.

Column =
RELATED ( Projects[P_name] )
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi,

 

I think the approach that you are using is correct, are you facing any performance issues.

 

Regards,

Pavan Vanguri.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors