Forum Discussion

GustavoKamchen's avatar
GustavoKamchen
Frequent Visitor
3 years ago
Solved

Filter Max hour by Date

Hello everybody.

 

I want to filter the table below to show me the column "Production" for the maximum hour of every day. How can I do this?

 

DateHourProduction
01/01/202205:00:0010
01/01/202206:00:0020
01/01/202207:00:0030
01/01/202208:00:0040
01/01/202209:00:0050
01/01/202210:00:0060
01/01/202211:00:0070
01/01/202212:00:0080
01/01/202213:00:0090
01/01/202214:00:00100
01/01/202215:00:00110
01/01/202216:00:00120
01/01/202217:00:00130
01/01/202218:00:00140
01/01/202219:00:00150
01/01/202220:00:00160
01/01/202221:00:00170
01/01/202222:00:00180
01/01/202223:00:00190
02/01/202205:02:039
02/01/202206:01:5918
02/01/202207:01:5527
02/01/202208:01:5136
02/01/202209:01:4745
02/01/202210:01:4354
02/01/202211:01:3963
02/01/202212:01:3572
02/01/202213:01:3181
02/01/202214:01:2790
02/01/202215:01:2399
02/01/202216:01:19108
02/01/202217:01:15117
02/01/202218:01:11126
02/01/202219:01:07135
02/01/202220:01:03144
02/01/202221:00:59153
02/01/202222:00:55162
  • Anonymous's avatar
    Anonymous
    3 years ago

    HI GustavoKamchen,

    You can create a calculated column with the following formula to use the current date to find 'hour', then use the above 'hour' and current date to get the corresponding Production values.

    formula =
    VAR _maxhour =
        CALCULATE (
            MAX ( Table[Hour] ),
            FILTER ( Table, [Date] = EARLIER ( Table[Date] ) )
        )
    RETURN
        CALCULATE (
            MAX ( Table[Production] ),
            FILTER ( Table, [Date] = EARLIER ( Table[Date] ) && [Hour] = _maxhour )
        )

    EARLIER, EARLIEST – DAX Guide - SQLBI

    Regards,

    Xiaoxin Sheng

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI GustavoKamchen,

    You can create a calculated column with the following formula to use the current date to find 'hour', then use the above 'hour' and current date to get the corresponding Production values.

    formula =
    VAR _maxhour =
        CALCULATE (
            MAX ( Table[Hour] ),
            FILTER ( Table, [Date] = EARLIER ( Table[Date] ) )
        )
    RETURN
        CALCULATE (
            MAX ( Table[Production] ),
            FILTER ( Table, [Date] = EARLIER ( Table[Date] ) && [Hour] = _maxhour )
        )

    EARLIER, EARLIEST – DAX Guide - SQLBI

    Regards,

    Xiaoxin Sheng

  • PVO3's avatar
    PVO3
    Icon for Impactful Individual rankImpactful Individual

    If you would like to create a table:

    Table =
    SUMMARIZE(
        Data,
        Data[Date],
        "Hour",
        MAX(Data[Hour]),
        "Production",
        CALCULATE(MIN(Data[Production]), SELECTEDVALUE(Data[Date])=Data[Date], MAX(Data[Hour]) = Data[Hour])
    )

     

    Result:

    You might want to format or change the hour column according to your needs.