Forum Discussion
Stumped, cannot get min date
Help.
I've tried way too many things, including
Min StLevCompYar =
var vIDontWork = (minx (FILTER('Milestones Info', 'Milestones Info'[Study] = SELECTEDVALUE('Milestones Info'[Study]) ), 'Milestones Info'[StudyLevel Completed Date] ))
//var vIAlsoDontWork = CALCULATE(min('Milestones Info'[StudyLevel Completed Date], ALLEXCEPT('Milestones Info','Milestones Info'[STUDY_SEQ])))
var v_min = CALCULATE(min('Milestones Info'[StudyLevel Completed Date]), ALLEXCEPT('Milestones Info','Milestones Info'[STUDY_SEQ]))
var vUse_min = CALCULATE(MIN('Milestones Info'[StudyLevel Completed Date]), FILTER('Milestones Info',year(v_min) = SELECTEDVALUE('Milestones Info'[StudyLevel Completed Date])))
var vxx = CALCULATETABLE(SELECTCOLUMNS('Milestones Info','Milestones Info'[STUDY_SEQ],'Milestones Info'[StudyLevel Completed Date]))
var vMinxx = MINx (VALUES( 'Milestones Info'[StudyLevel Completed Date]), 'Milestones Info'[StudyLevel Completed Date])
return
vIDontWorkNone of the above work. I've spent over four hours on this and am ready to say what I need can't be done in power bi.
Made up Data sample:
Results:
Eventually I just want the year, but this shows thaty it just giving me the current row. Can someone please solve this for me.
thx
SOLVED
This is really crazy to me, so I would love an explanation from someone.
Data is such that a value for study_seq will always have the same value for title-id and vice-versa. I changed my formula to use title-ID which DOES appear in the table instead of study_seq. I now get the correct response.Someone, Ritaf1983 ? maruthisp ? please explain this too me.
5 Replies
- Ashish_Mathur
Super User
Hi,
Please share data in a format that can be pasted in an MS Excel file. Also, clearly show the expected result.
- maruthisp
Super User
Hi jjustjjo,
Can you try below steps:
1. Create the minimum date measure
If STUDY_SEQ identifies the study/group for which you want the earliest completed date, create this measure:Min Study Level Completed Date = CALCULATE ( MIN ( 'Milestones Info'[StudyLevel Completed Date] ), ALLEXCEPT ( 'Milestones Info', 'Milestones Info'[STUDY_SEQ] ) )
This is a measure, not a calculated column.
ALLEXCEPT removes the filters coming from the other columns in Milestones Info, including the current row's completed date, while keeping the current STUDY_SEQ filter.
So for every row belonging to the same STUDY_SEQ, you should now get the same earliest date.
2. If you only want the yearOnce the minimum date is working, you can return only the year:
Min Study Level Completed Year = VAR MinCompletedDate = CALCULATE ( MIN ( 'Milestones Info'[StudyLevel Completed Date] ), ALLEXCEPT ( 'Milestones Info', 'Milestones Info'[STUDY_SEQ] ) ) RETURN YEAR ( MinCompletedDate )
Best Regards,
Maruthi
LinkedIn - http://www.linkedin.com/in/maruthi-siva-prasad/
X - Maruthi Siva Prasad - (@MaruthiSP) / X - Ritaf1983
Super User
Hi jjustjjo
It’s not impossible, it’s filter context. Because the date columns are in your table visual, each row filters the measure down to that single date, so MIN just returns the current row. FILTER(‘Milestones Info’, ...) doesn’t help either, since it iterates the table after that filter is applied.
Remove the row-level filters and keep only the study:
Min StLevCompYear = VAR _min = CALCULATE( MIN('Milestones Info'[StudyLevel Completed Date]), ALLEXCEPT('Milestones Info', 'Milestones Info'[study_seq]) ) RETURN YEAR(_min)
This returns 2023 on every row for study 52.
Note: ALLEXCEPT also ignores slicers on other columns of that table. If you have those, use REMOVEFILTERS on just the columns in your visual instead:
CALCULATE( MIN('Milestones Info'[StudyLevel Completed Date]), REMOVEFILTERS('Milestones Info'[StudyLevel Completed Date], 'Milestones Info'[SiteLevel Completed Date], 'Milestones Info'[Milestone]), 'Milestones Info'[Milestone level] = "Study" )
Same idea fixes your line chart: if the axis uses a date table, add it to REMOVEFILTERS inside the measures that feed the DATEDIFF.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly. - jjustjjo
Helper II
Thank you both maruthisp and Ritaf1983
I am using a measure.
Update 3:45 PM EDT: I found a misplaced parentheses. Now that I have that correction, , to wit:var vIAlsoDontWork = CALCULATE(min('Milestones Info'[StudyLevel Completed Date]), ALLEXCEPT('Milestones Info','Milestones Info'[STUDY_SEQ]))All rows return 01-Jan-1990, even though the earliest date for my study_seq is 19-Apr-2023.
I did just realize that my made-up sample does leave out a layer. The sample is more like this:
study_seq Milestone Milestone level Site Name StudyLevel Comp Date SiteLevel Comp Date 52 A Study Site 1 19-Apr-2023 52 B Study Site 1 28-Jun-2023 52 M Site Site 1 25-Nov-2025 25-Nov-2025 52 N Site Site 1 28-Oct-2025 28-Oct-2025 52 O Site Site 1 27-Nov-2025 27-Nov-2025 52 A Study Site 2 19-Apr-2023 52 B Study Site 2 28-Jun-2023 52 M Site Site 2 25-Nov-2025 52 N Site Site 2 28-Oct-2025 52 O Site Site 2 27-Nov-2025 So you have the added complexity multiple site names. But I don't think this would affect the method of getting the Min date out of StudyLevel Comp Date.
- jjustjjo
Helper II
SOLVED
This is really crazy to me, so I would love an explanation from someone.
Data is such that a value for study_seq will always have the same value for title-id and vice-versa. I changed my formula to use title-ID which DOES appear in the table instead of study_seq. I now get the correct response.Someone, Ritaf1983 ? maruthisp ? please explain this too me.