Forum Discussion

aar0n's avatar
aar0n
Advocate II
8 years ago
Solved

How to make a calculated 'days' column

Hours OnlineDateLocationDays OnlineProduction
01/1/2017A00
01/2/2017A00
121/3/2017A15
241/4/2017A210
241/5/2017A35
241/6/2017A420
01/8/2017B00
01/9/2017B00
01/10/2017B00
241/11/2017B15
241/12/2017B25
51/13/2017B25
101/14/2017B210
241/15/2017B320

The first 3 columns is what i have, and the 4th column is what i would like to calculate. 

 

Basically, i want to convert the 'hours online' values into a 'days online'.  im trying to get a calculation that will sum all the hours, and only add 1 day to the to the 'days online' value if the sum is 24. 

 

I am trying to plot 'Days online' on the x axis, and 'Production' on the Y-axis - for both locations, so that i can compare how each location performs relative to each other.

  • HI aar0n

     

    Try this Calculated Column

     

    Column =
    VAR myDaysOnline =
        CALCULATE (
            COUNTROWS ( TableName ),
            FILTER (
                ALLEXCEPT ( TableName, TableName[Location] ),
                TableName[Hours Online] = 24
                    && TableName[Date] <= EARLIER ( TableName[Date] )
            )
        )
    RETURN
        IF ( ISBLANK ( myDaysOnline ), 0, myDaysOnline )
  • HI aar0n

     

    In that case use this Column

     

    Column =
    VAR CumulativeHours =
        CALCULATE (
            SUM ( TableName[Hours Online] ),
            FILTER (
                ALLEXCEPT ( TableName, TableName[Location] ),
                TableName[Date] <= EARLIER ( TableName[Date] )
            )
        )
    RETURN
        ROUNDDOWN ( DIVIDE ( CumulativeHours, 24 ), 0 )
  • HI aar0n

     

    Please could you try this

     

    Just Replaced ROUNDDown with QUOTIENT

     

    Column =
    VAR CumulativeHours =
        CALCULATE (
            SUM ( TableName[Hours Online] ),
            FILTER (
                ALLEXCEPT ( TableName, TableName[Location] ),
                TableName[Date] <= EARLIER ( TableName[Date] )
            )
        )
    RETURN
        QUOTIENT ( CumulativeHours, 24 )

10 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi aar0n,

     

    I'm still not get your calculation logic, can you provide more details information about this?
    At first 3 rows, total hours is twelve, why did you log it as one day? (as you said, if sum 24 hours then you will log it as one day)


    Or the 'days online' is a stand alone column who already used to store values?

     

    Regards,

    Xiaoxin Sheng

    • aar0n's avatar
      aar0n
      Advocate II

      that was a typo - it should say 24 hours instead of 12!! sorry for that, i missed it.

      • Zubair_Muhammad's avatar
        Zubair_Muhammad
        Community Champion

        HI aar0n

         

        Try this Calculated Column

         

        Column =
        VAR myDaysOnline =
            CALCULATE (
                COUNTROWS ( TableName ),
                FILTER (
                    ALLEXCEPT ( TableName, TableName[Location] ),
                    TableName[Hours Online] = 24
                        && TableName[Date] <= EARLIER ( TableName[Date] )
                )
            )
        RETURN
            IF ( ISBLANK ( myDaysOnline ), 0, myDaysOnline )