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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
thainonne
Frequent Visitor

Get first date of column based on criteria

Hi community,

 

I checked many posts now but could not get an answer to the following:

 

I am trying to create a calculated column which shows only the first date of a related column in the same table in the respective row which contains the first value. Even if there is a second row which also contains the first date, it should be shown as blank because it would be a duplicate.

I have tried to create one with MINX, MIN, TOPN etc. but it either showed the first column of the whole dataset or shows the date if it is not blank but does not react to any further filter criteria I have applied in DAX.

 

Table:

Column "Requisition ID" and "Screen Date" exist and the third column "First screen date" is the calculated column I want to create.

 

Many thanks in advance,

Marvin

 

Requisition IDScreen Date (DD.MM.YY)First screen date (DD.MM.YY)
R101.01.2101.01.21
R101.01.21 
R203.02.2103.02.21
R305.01.2105.01.21
R112.02.21 
R222.02.21 
R417.02.2117.02.21
R118.01.21 
R302.02.21 
1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @thainonne ,

According to your description, here's my solution.

1.Add an index column in Power Query.

2.Create a calculated column:

Column =
VAR _MINDATE =
    MINX (
        FILTER (
            'Table',
            'Table'[Requisition ID] = EARLIER ( 'Table'[Requisition ID] )
        ),
        'Table'[Screen Date (DD.MM.YY)]
    )
VAR _MINDEX =
    MINX (
        FILTER (
            'Table',
            'Table'[Requisition ID] = EARLIER ( 'Table'[Requisition ID] )
                && 'Table'[Screen Date (DD.MM.YY)] = EARLIER ( 'Table'[Screen Date (DD.MM.YY)] )
        ),
        'Table'[Index]
    )
RETURN
    IF (
        [Screen Date (DD.MM.YY)] = _MINDATE
            && [Index] = _MINDEX,
        [Screen Date (DD.MM.YY)]
    )

Get the correct result:

vyanjiangmsft_0-1686730444330.png

I attach my sample below for your reference.

 

Best regards,

Community Support Team_yanjiang

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-yanjiang-msft
Community Support
Community Support

Hi @thainonne ,

According to your description, here's my solution.

1.Add an index column in Power Query.

2.Create a calculated column:

Column =
VAR _MINDATE =
    MINX (
        FILTER (
            'Table',
            'Table'[Requisition ID] = EARLIER ( 'Table'[Requisition ID] )
        ),
        'Table'[Screen Date (DD.MM.YY)]
    )
VAR _MINDEX =
    MINX (
        FILTER (
            'Table',
            'Table'[Requisition ID] = EARLIER ( 'Table'[Requisition ID] )
                && 'Table'[Screen Date (DD.MM.YY)] = EARLIER ( 'Table'[Screen Date (DD.MM.YY)] )
        ),
        'Table'[Index]
    )
RETURN
    IF (
        [Screen Date (DD.MM.YY)] = _MINDATE
            && [Index] = _MINDEX,
        [Screen Date (DD.MM.YY)]
    )

Get the correct result:

vyanjiangmsft_0-1686730444330.png

I attach my sample below for your reference.

 

Best regards,

Community Support Team_yanjiang

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

 

@v-yanjiang-msft  many thanks - this solved the problem. 

Cheers and again thank you!

AjithPrasath
Resolver II
Resolver II

@thainonne ,

  Hi, can you try the below code?

FirstScreenDate =
VAR CurrentRequisitionID = 'YourTable'[Requisition ID]
VAR MinDate =
    CALCULATE(
        MIN('YourTable'[Screen Date (DD.MM.YY)]),
        ALLEXCEPT('YourTable', 'YourTable'[Requisition ID])
    )
RETURN
    IF('YourTable'[Requisition ID] = CurrentRequisitionID && 'YourTable'[Screen Date (DD.MM.YY)] = MinDate, MinDate, BLANK())

Please let me know if you have any issues

 

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

@AjithPrasath Many thanks for the quick response.

I have tried your solution and it does pull the first date. However, it still shows multiple rows if e.g. three rows for the same Requisition ID have the same screen date.

I need only the first occuring row so to say even if the same date comes up a second, third,... time for the same Requisition ID.

 

Is this something which can also be entered in the DAX formula?

 

Thank you

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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