Forum Discussion

Andy1927's avatar
Andy1927
Helper I
5 years ago
Solved

Date Bins / Groups

Hi,   I'm having to rebuild my PowerBI report because some column names in the live data source have changed. Is it possible to create a conditional column in Power Query where I can group the time...
  • v-deddai1-msft's avatar
    v-deddai1-msft
    5 years ago

    Hi Andy1927 ,

     

    You can use dax to create a calculated column, it is much simpler than use power query, you can try to use the following calculated column:

     

    BINS =
    VAR A =
        DATEDIFF ( TODAY (), Table[End Date], MONTH )
    RETURN
        IF (
            ISBLANK ( Table[End Date] ),
            BLANK (),
            SWITCH (
                TRUE (),
                A <= 2, "0-2mths",
                A >= 3
                    && A <= 5, "3-5mths",
                A >= 6
                    && A <= 11, "6-11mths",
                A >= 24, "24mth+"
            )
        )

     

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

     

    Best Regards,

    Dedmon Dai