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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
tcburge3
Helper I
Helper I

Need help with returning the maximumum date in a subset of data created with variables

Hello,

 

I am having trouble returning the maximum date in a range when using variables to filter my data.

 

I have this column ("[Column]") in my table that has some duplicate values. I want to grab the maximum (latest) date in [created_at_stg3] in all instances where my [column] is duplicated.

 

I have already created this [duplicate] column with dax, using variables, that correctly identifies rows where [column] is duplicated. 

Here is my [Duplicates] column. This column is working fine. (text format of this column is pasted at the end of this post).

tcburge3_0-1712351862897.png

 

The column I need help with is [max duplicate date]. I would like to return the largest/latest [created_at_stg3] value for all instances where [column] is duplicated (this is also indicated by the [Duplicates] column). Currently, This is my formula that returns the [created_at_stg3] value for each row that is duplicated, but I want to return the maximum [created_at_stg3] value for each row where [column] is duplicated. I have highlighted the value that I want to be provided by this column in the snip below. I would like to return BLANK() for any rows where [column] is not duplicated, but that is not entirely necessary.

tcburge3_1-1712352279727.png

As you can see, I want the highlighted date under [created_at_stg3] to be returned under [max duplicate date], for both yellow and green.

 

Eventually, I will use the following IF statement to filter out rows that do not have the maximum [created_at_stg3] for any rows where [column] is duplicated. 

Duplicates to be filtered out =

IF(AND([duplicates]=”Duplicate”,[Max Duplicate Date]<>[created_st_stg3]),1,0)

 

But first, I need help with returning this max [created_at_stg3] for rows where [column] is duplicated.

 

Please let me know if you have any thoughts or solutions, and of course I am happy to answer any questions. Your time is appreciated, thank you!

 

Here are the text formats of my 2 columns mentioned here. My table name is 'stg1_2_3vw1_dev'.

1.

[Duplicates] =

VAR varCurrentValue = 'stg1_2_3_vw1_dev[Column]

VAR varInstances =

    COUNTROWS(

        FILTER(

            'stg1_2_3_vw1_dev’,

            'stg1_2_3_vw1_dev’[Column] = varCurrentValue

        )

    )

var Result =

    IF(

        varInstances > 1,

        "Duplicate",

        "Unique"

    )

RETURN

    Result

 

 

2.

[max duplicate date] =

VAR varCurrentValue = 'stg1_2_3_vw1_dev'[Column]

VAR varInstances =

    COUNTROWS(

        FILTER(

            'stg1_2_3_vw1_dev',

            'stg1_2_3_vw1_dev'[Column] = varCurrentValue

        )

    )

var Result =

    IF(

        varInstances > 1,

        ([created_at_stg3]),

        BLANK()

    )

RETURN

    Result

1 ACCEPTED SOLUTION
v-jiewu-msft
Community Support
Community Support

Hi @tcburge3 ,

Based on my testing, please try the following methods:

1.Create the sample table.

vjiewumsft_0-1712561887380.png

2.Create the measure to return the largest date for instances where column is duplicated.

 

max Duplicates date = 
VAR varCurrentValue = 'stg1_2_3vw1_dev'[Column]
VAR varInstances =
    COUNTROWS(
        FILTER(
            'stg1_2_3vw1_dev',
            'stg1_2_3vw1_dev'[Column] = varCurrentValue
        )
    )
VAR varMaxDate = CALCULATE(
    MAX('stg1_2_3vw1_dev'[created_at_stg3]),
    FILTER(
        'stg1_2_3vw1_dev',
        'stg1_2_3vw1_dev'[Column] = varCurrentValue
    )
)
var Result =
    IF(
        varInstances > 1,
        varMaxDate,
        BLANK()
    )
Return
    Result

 

3.Drag the measure into the table visual. The result is shown below.

vjiewumsft_1-1712561934172.png

Best Regards,

Wisdom Wu

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

3 REPLIES 3
v-jiewu-msft
Community Support
Community Support

Hi @tcburge3 ,

Based on my testing, please try the following methods:

1.Create the sample table.

vjiewumsft_0-1712561887380.png

2.Create the measure to return the largest date for instances where column is duplicated.

 

max Duplicates date = 
VAR varCurrentValue = 'stg1_2_3vw1_dev'[Column]
VAR varInstances =
    COUNTROWS(
        FILTER(
            'stg1_2_3vw1_dev',
            'stg1_2_3vw1_dev'[Column] = varCurrentValue
        )
    )
VAR varMaxDate = CALCULATE(
    MAX('stg1_2_3vw1_dev'[created_at_stg3]),
    FILTER(
        'stg1_2_3vw1_dev',
        'stg1_2_3vw1_dev'[Column] = varCurrentValue
    )
)
var Result =
    IF(
        varInstances > 1,
        varMaxDate,
        BLANK()
    )
Return
    Result

 

3.Drag the measure into the table visual. The result is shown below.

vjiewumsft_1-1712561934172.png

Best Regards,

Wisdom Wu

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

Thank you! This is just what I'm looking for. Accepted it as the solution. Thank you so much for your help.

tcburge3
Helper I
Helper I

just to reiterate. [max duplicate date] is the column I need help with. In the highlighted snip, I want the yellow value under [created_at_stg3] to be returned for both of the highlighted rows under [max duplicate date]. And the same for the green highlighted values. Thank you so much! Sorry if I am a bit of an over-explainer

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.