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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
kza40381
Frequent Visitor

Find min date within a group in a heirarchy

Hi All,

 

I have a union query which includes study, country and site level data and milestones.  I am using a matrix to display the heirarchal view of the data.  Therefore, you would have a study row, then a row for each Region beneath, then the sites for the Region, beneath Region.

 

I need to create 4 columns, with logic, which result in a 1 if:

  • the site date is less than the region date for a patricular study
  • the site date is less than the study date for the study
  • if the min date of all the regions of a study is earlier than the study level milestone
  • a column that results in a 1 if the study has a site or region date which is less than the study level date. 

Below is an example of what I am looking for.  I hope you can help me.Sample for PBI.PNG

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @kza40381 ,

 

I am so glad to help you solve your problem. Please kindly Accept it as the solution. More people will benefit from it. 

 

Best Regards,
Rico Zhou

 

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

7 REPLIES 7
lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue. If you paste the data into a table in your post or use one of the file services it will be easier to work with. Avoid posting screenshots of your source data if possible.

Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.


Thank you for your response.  Is this helpful?

Heirarchy levelStudy #CountrySiteFSISite FSI < Region FSISite FSI < Study FSIMin Region < StudyStudy has either Region or Site FSI  which is < Study FSI
Study1  8/15/2018   1
Region1Israel 3/29/20190 00
Site1Israel972110/31/20180000
Site1Israel972211/13/20180 00
Site1Israel9723(Blank)0000
Region1Italy 1/1/20170010
Site1Italy39013/5/20161100
Site1Italy39027/1/20161100
Site1Italy39038/21/20180000
Study2  10/15/2018   1
Region2Netherlands 5/1/20170010
Site2Netherlands31014/1/20190000
Region2Spain 10/2/20180010
Site2Spain34019/1/20171100
Site2Spain34025/1/20161100
Region2Sweden 12/22/20210000
Site2Sweden46015/2/20191100
Region2United Kingdom 3/2/20190000
Anonymous
Not applicable

Hi @kza40381 ,

 

Try codes as below to create calcualted columns.

Site FSI < Region FSI = 
VAR _REGIN_DATE =
    CALCULATE (
        MIN ( 'Table'[FSI] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Study #], 'Table'[Country] ),
            'Table'[Heirarchy level] = "Region"
        )
    )
RETURN
    IF (
        'Table'[Heirarchy level] = "Study",
        BLANK (),
        IF ( 'Table'[FSI] < _REGIN_DATE && 'Table'[FSI] <> BLANK (), 1, 0 )
    )
Site FSI < Study FSI = 
VAR _STUDY_DATE =
    CALCULATE (
        MIN ( 'Table'[FSI] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Study #] ),
            'Table'[Heirarchy level] = "Study"
        )
    )
RETURN
    IF (
        'Table'[Heirarchy level] = "Study",
        BLANK (),
        IF (
            'Table'[FSI] < _STUDY_DATE
                && 'Table'[FSI] <> BLANK ()
                && 'Table'[Heirarchy level] = "Site",
            1,
            0
        )
    )
Min Region < Study = 
VAR _STUDY_DATE =
    CALCULATE (
        MIN ( 'Table'[FSI] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Study #] ),
            'Table'[Heirarchy level] = "Study"
        )
    )
RETURN
    IF (
        'Table'[Heirarchy level] = "Study",
        BLANK (),
        IF ( 'Table'[Heirarchy level] = "Region" && 'Table'[FSI] < _STUDY_DATE, 1, 0 )
    )
Study has either Region or Site FSI  which is < Study FSI = 
VAR _COUNT_SITE =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Study #] ),
            'Table'[Site FSI < Study FSI] = 1
        )
    )
VAR _COUNT_REGION =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Study #] ),
            'Table'[Min Region < Study] = 1
        )
    )
RETURN
    IF (
        'Table'[Heirarchy level] = "Study"
            && _COUNT_REGION + _COUNT_SITE > 0,
        1,
        0
    )

Result is as below.

1.png

I think [Site FSI < Region FSI] in Study# =1 Country = Israel and [Site FSI < Study FSI] in Study# =2 Country = Sweden are not the same like yours.

 

Best Regards,
Rico Zhou

 

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

Hi Rico,

I can't tell you how excited I am.  I just replaced all of the generic names in your code noted in my sample in all of the columns you prepared.  They all worked!  I am so thrilled as I have been working on this for weeks and new it was about filtering and all accept.  Just couldn't get it right as I am very novice to power BI and Dax.  Please let me know how I can give you the highest rating on this complicated task/solution.  I also appreciate you caught the mistake in my sample.  Thank you for that!

 

Anonymous
Not applicable

Hi @kza40381 ,

 

I am so glad to help you solve your problem. Please kindly Accept it as the solution. More people will benefit from it. 

 

Best Regards,
Rico Zhou

 

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

Yes, this helps.  However the expected result doesn't seem to match your logic. For example for Israel the first two site FSIs are lower than the region FSI yet they are not marked?

 

See attached for a proposal on the first extra column.

 

lbendlin_0-1646694041115.png

 

Thank you so much for responding Ibendlin.  As noted above, Rico was able to solve my issues.  I can't tell you how appreciative I am that all of you in this community are willing to help those of us who struggle trying to figure things out.  You are all brilliant!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.