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
ClemFandango
Helper II
Helper II

What is the best method for calculating min/max dates in a column?

Hi there,

I am hoping someone can help.

I am trying to calculate the ‘min start date’ of ‘acc name’ in power query (as per table below).

ClemFandango_0-1678987193976.png

 

I am using this in Power Query - List.Min(Table.SelectRows(#"Changed Type",(x)=>x[Acc Name]=[Acc Name])[Start Date]) but it takes absolutely ages (hours) - presumably because I have 90k+ rows.

 

I have also tried doing the same thing as New Column in DAX and it works much quicker:-

MinDate = CALCULATE (

        MIN ( Cust [Ent all.Start Date] ),

        ALLEXCEPT( Cust, Cust [Acc Name] )

    )

 

However, I want to calculate the MinDate in my calendar table as below, but neither calculated columns MinDate or MaxDate are available to use in the ‘Count’ calculated column. 

Count =

COUNTROWS (

    FILTER (

        'Ent all',

        [MMYYDD] <= 'Ent all'[MinDate]

            && [MMYYDD] < 'Ent all'[MaxDate]

    )

)

 

My final output should look something like this….

 

ClemFandango_1-1678987262592.png

 

I am trying to count the rows where MMYYDD is inside the min & max dates, but neither calculated columns MinDate or MaxDate are available to use in the ‘Count’ calculated column of my date table. Am I doing something incredibly stupid?

Any help greatly appreciated.

 

Many thanks CF

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @ClemFandango 

 

You can try the following methods.

Min Date = CALCULATE(MIN('Table'[Start Date]),ALLEXCEPT('Table','Table'[Acc Name]))
Max Date = CALCULATE(MAX('Table'[Start Date]),ALLEXCEPT('Table','Table'[Acc Name]))

vzhangti_0-1679383968034.png

Column:

Count = 
CALCULATE ( COUNT ( 'Table'[Acc Name] ),
    FILTER ( ALL ( 'Table' ),
        [Min Date] <= EARLIER ( 'Date'[MMYYDD] )
            && [Max Date] >= EARLIER ( 'Date'[MMYYDD] )
    )
)

vzhangti_1-1679384022120.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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-zhangti
Community Support
Community Support

Hi, @ClemFandango 

 

You can try the following methods.

Min Date = CALCULATE(MIN('Table'[Start Date]),ALLEXCEPT('Table','Table'[Acc Name]))
Max Date = CALCULATE(MAX('Table'[Start Date]),ALLEXCEPT('Table','Table'[Acc Name]))

vzhangti_0-1679383968034.png

Column:

Count = 
CALCULATE ( COUNT ( 'Table'[Acc Name] ),
    FILTER ( ALL ( 'Table' ),
        [Min Date] <= EARLIER ( 'Date'[MMYYDD] )
            && [Max Date] >= EARLIER ( 'Date'[MMYYDD] )
    )
)

vzhangti_1-1679384022120.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

Amazing stuff! Thank you v-zhangti

ClemFandango
Helper II
Helper II

Or to put it a bit simpler....

 

I am trying to achieve the following table

ClemFandango_0-1678991444670.png

 

The ‘Count’ column should be calculated as below, but the ‘MinDate’ & ‘MaxDate’ calculated columns are in a different table, so I am unable to use them in my calculations.

Count =

COUNTROWS (

    FILTER (

        'Ent all',

        [MMYYDD] <= 'Ent all'[MinDate]

            && [MMYYDD] < 'Ent all'[MaxDate]

    )

)

 

Do you have any idea of a method that will allow me to use the mindate & maxdate in my calculations?

 

Any help greatly appreciated,

 

CF

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.