Forum Discussion

AvPowerBI's avatar
AvPowerBI
Icon for Post Patron rankPost Patron
6 years ago
Solved

DAX - GROUP BY, MIN, AVERAGE

Hi,

 

I want to do the following but not sure if it can be done in one DAX Measure or a combination of DAX, Calculated Columns etc...

 

First of all I have two tables

Visits

EngineerCalendar

 

The Visits Table I have the following fields

 

EngineerId

ArriveDate

ArriveTimeSec

 

I want the MIN for ArriveTimeSec Group By EngineerId, ArriveDate

 

I then want to AVERAGE the above GROUP BY and convert the Field ArriveTimeSec to be the fomat of HH:SS 

 

I have the below DAX but I cannot include the AVERAGE with the DAX formula failing

 

Avg 1st Arr Time =

VAR _AvgTime = CALCULATE(MIN(Visits[ArriveTimeSec]), CROSSFILTER(EngineerCalendar[CalendarKey], Visits[CalendarKey], Both))

VAR _Hrs = FLOOR(_AvgTime / 3600, 1)

VAR _Min = FLOOR(MOD(_AvgTime, 3600) / 60, 1)

RETURN

IF(

ISBLANK(_Hrs),

BLANK(),

RIGHT("0" & _Hrs, 2) & ":" & RIGHT("0" & _Min, 2)

)

 

Thanks

 

 

 

  • Hi AvPowerBI ,

     

    I guess you need to add fields from different tables to the same visual, so it is necessary to establish a relationship between the three tables.

     

    ā€œ

    Also I then created the Calculated Column Avg_time, do I then have to create another calculated column to do the following

    Format = FORMAT( [Avg_time], "HH:SS")

    "

    If you need the returned result of this calculated column, just create it, or you can combine this formula with the Avg_time formula.

     

    Best regards,
    Lionel Chen

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

     

     

7 Replies