Forum Discussion

MHTANK's avatar
MHTANK
Helper III
1 year ago
Solved

10 Days Range

Date 01-01-2025 02-01-2025 04-01-2025 05-01-2025 07-01-2025 08-01-2025 09-01-2025 10-01-2025 15-01-2025 17-01-2025 20-01-2025 22-01-2025 30-01-2025 01-02-...
  • vojtechsima's avatar
    vojtechsima
    1 year ago

    Hey man, danextian ,

    you forgot about leap year:

    You can do this instead:

    Date Range = 
    VAR _DayOfMonth =
        DAY ( 'Table'[Column1] )
    VAR _DaysInMonth =
        DAY ( EOMONTH ( 'Table'[Column1], 0 ) )
    RETURN
        SWITCH (
            TRUE (),
            _DayOfMonth <= 10, "1-10",
            _DayOfMonth <= 20, "11-20",
            "21-"&_DaysInMonth
        )
  • DataNinja777's avatar
    1 year ago

    Hi MHTANK ,

     

    You can create the Day_Range column in DAX using a calculated column formula. The formula first extracts the day from the date using DAY('Table'[Date]). Then, it determines the last day of the month using EOMONTH('Table'[Date], 0). The SWITCH(TRUE(), ...) function is used to assign the appropriate range: values between 1 and 10 are labeled "1-10," values between 11 and 20 are labeled "11-20," and values from 21 onward are dynamically assigned using "21-" & FORMAT(MonthEnd, "0"), ensuring that the last day of each month is correctly considered, whether it's 28, 30, or 31 days.

    Day_Range = 
    VAR DayNum = DAY('Table'[Date])
    VAR MonthEnd = DAY( EOMONTH('Table'[Date], 0) ) 
    RETURN
        SWITCH(
            TRUE(),
            DayNum <= 10, "1-10",
            DayNum <= 20, "11-20",
            "21-" & FORMAT(MonthEnd, "0")
        )
    

    Replace 'Table' with the actual name of your table in Power BI. This formula ensures that the correct 10-day grouping is applied while dynamically adjusting for different month lengths.

     

    Best regards,

  • Ashish_Mathur's avatar
    1 year ago

    Hi,

    Try this calculated column formula

    Column = if(DAY(Data[Date])<=10,"1-10",if(day(Data[Date])<=20,"11-20","21-"&day(EOMONTH(Data[Date],0))))

    Hope this helps.

     

  • vojtechsima's avatar
    vojtechsima
    1 year ago

    MHTANK  I am not exactly sure what you mean, but you can do  in Power Querry:
    Add Column and then copy just this part:

    let
        daysInMonth = Date.DaysInMonth([Date]),
        currentDay = Date.Day([Date]),
        createText = 
        if currentDay <= 10 then "1-10" 
        else if currentDay <= 20 then "11-20" 
        else "21-"&Text.From(daysInMonth)
    in
        createText