Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

conditional column and dax calculations

good afternoon masters   Again I am in the need to come to his knowledge, I happen to be making a report and I have encountered several difficulties, (including lack of creativity) :smileyfrustrate...
  • pawel1's avatar
    7 years ago

    Hi,

    1st - your formula for grouping hours would work if you sort the hours from the latest to the earliest:

    rango_horario = SWITCH(TRUE(),
                        hurto_personal[hora] >= TIME(22,00,00),"10 - 12 pm",
                        hurto_personal[hora] >= TIME(20,00,00),"8 - 10 pm",
                        hurto_personal[hora] >= TIME(18,00,00),"6 - 8 pm",
                        hurto_personal[hora] >= TIME(16,00,00),"4 - 6 pm",
                        hurto_personal[hora] >= TIME(14,00,00),"2 - 4 pm",
                        hurto_personal[hora] >= TIME(12,00,00),"12 - 2 pm",
                        hurto_personal[hora] >= TIME(10,00,00),"10 - 12 am",
                        hurto_personal[hora] >= TIME(08,00,00),"8 - 10 am",
                        hurto_personal[hora] >= TIME(06,00,00),"6 - 8 am",
                        hurto_personal[hora] >= TIME(04,00,00),"4 - 6 am",
                        hurto_personal[hora] >= TIME(02,00,00),"2 - 4 am",
                        hurto_personal[hora] >= TIME(12,00,00),"10 - 12 am","validar")
     
    2nd: I assume you need a formula for Compound Annual Growth Rate (CAGR), If so, you can write either a static one (valid for years 2010-2018 only):
     
    CAGR 2018vs2010 = 
    var Hurtos2010 = 
        CALCULATE([tot_hurtos], 
            Dates[Year] = 2010)
    var Hurtos2018 = 
        CALCULATE([tot_hurtos], 
            Dates[Year] = 2018)
    Return
    (Hurtos2018/Hurtos2010)^(1/8)-1

    or a dynamic one (for any selected years):

    CAGR dynamic = 
    var HurtosFirstYear = 
        CALCULATE([tot_hurtos], 
            FILTER(ALLSELECTED(Dates),Dates[Year] = MIN(Dates[Year])))
    var HurtosLastYear = 
        CALCULATE([tot_hurtos], 
            FILTER(ALLSELECTED(Dates),Dates[Year] = MAX(Dates[Year])))
    var NumberOfYears = 
        MAX(Dates[Year])-MIN(Dates[Year])
    Return
    (HurtosLastYear/HurtosFirstYear)^(1/NumberOfYears)-1

    aha, and you need a 'Dates' Table with at least two columns 'Date' and 'Year' to make it work.

    hope it helps, good luck!

    Pawel