Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
DAX Gurus, I need some help please. (I created some general data to use an example of my problem. )
Table1
First, I am trying to get the rank or order of each class start date by name and class. But if the same student in the same class has a start date and an end date that is earlier than a previous end date (same name and class) then remove it and don't rank it (example of this occurance is highlighted yellow).
I have been able to rank it with a calcuated column,
(=(RANKX(FILTER(TABLE1,TABLE1[NAME]=EARLIER(TABLE1[NAME])),[START DATE],[START Date],ASC))),
Next I was able to create a measure to remove the start date if it is earlier than the end date with a measure (have not attempted the end date, but should be similar). I was going to create measure with a line for each rank and started with 3 because I found an occurance with rank 3 in my data.
=Remove date:=if(and(TABLE1[Sum of Rank]=3,(CALCULATE(sum([START DATE]),TABLE1[CDP Category Sequence Occuring]=3))<(CALCULATE(sum([END DATE]),TABLE1[RANK]=2))),BLANK(),MIN([START DATE]))
But I cannot figure out how to not show the rows where the same student in the same class has a start date and an end date that is earlier than a previous end date (same name and class) and rank it afterwards.
This is what I would like it to look like.
I hope this makes sense. I am new to DAX and new this POWER BI Community so I hope you can understand what I am trying to do.
Thanks for any help.
Solved! Go to Solution.
Hi @wshanewood1 ,
Create a sorted calculated column by class and name.
Rank =
RANKX (
FILTER (
ALL ( 'Table' ),
'Table'[CLASS] = EARLIER ( 'Table'[CLASS] )
&& 'Table'[NAME] = EARLIER ( 'Table'[NAME] )
),
[START DATE],
,
ASC,
DENSE
)
Create a Flag column whose start date and end date are greater than the previous end date.
Flag =
VAR _endpre =
CALCULATE (
MAX ( 'Table'[END DATE] ),
FILTER (
'Table',
[NAME] = EARLIER ( 'Table'[NAME] )
&& 'Table'[CLASS] = EARLIER ( 'Table'[CLASS] )
&& 'Table'[Rank]
= EARLIER ( 'Table'[Rank] ) - 1
)
)
RETURN
IF ( [START DATE] > _endpre && [END DATE] > _endpre, 1 )
Create a measure to get the result.
Expected Result =
IF (
MAX ( 'Table'[Flag] ) <> BLANK (),
RANKX (
FILTER (
ALL ( 'Table' ),
[CLASS] = MAX ( 'Table'[CLASS] )
&& [NAME] = MAX ( 'Table'[NAME] )
&& [Flag] <> BLANK ()
),
CALCULATE ( MAX ( 'Table'[START DATE] ) ),
,
ASC,
DENSE
)
)
You can check details from the attachment.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @wshanewood1 ,
Create a sorted calculated column by class and name.
Rank =
RANKX (
FILTER (
ALL ( 'Table' ),
'Table'[CLASS] = EARLIER ( 'Table'[CLASS] )
&& 'Table'[NAME] = EARLIER ( 'Table'[NAME] )
),
[START DATE],
,
ASC,
DENSE
)
Create a Flag column whose start date and end date are greater than the previous end date.
Flag =
VAR _endpre =
CALCULATE (
MAX ( 'Table'[END DATE] ),
FILTER (
'Table',
[NAME] = EARLIER ( 'Table'[NAME] )
&& 'Table'[CLASS] = EARLIER ( 'Table'[CLASS] )
&& 'Table'[Rank]
= EARLIER ( 'Table'[Rank] ) - 1
)
)
RETURN
IF ( [START DATE] > _endpre && [END DATE] > _endpre, 1 )
Create a measure to get the result.
Expected Result =
IF (
MAX ( 'Table'[Flag] ) <> BLANK (),
RANKX (
FILTER (
ALL ( 'Table' ),
[CLASS] = MAX ( 'Table'[CLASS] )
&& [NAME] = MAX ( 'Table'[NAME] )
&& [Flag] <> BLANK ()
),
CALCULATE ( MAX ( 'Table'[START DATE] ) ),
,
ASC,
DENSE
)
)
You can check details from the attachment.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Please provide sample data in usable format (not as a picture) .
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
113 | |
108 | |
98 | |
39 | |
30 |