Forum Discussion

Ibrahim_shaik's avatar
2 years ago
Solved

How to Aggregate Data Per Day, Week, Month, Year in Line Chart

Hi Power BI Community,   I have a table with Date Column which has date, month, year in it like Thursday, March07, 2024 and  a time column with a 5 minute time interval timestamp for 24 hours and I...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi  Ibrahim_shaik ,

     

    lbendlin , thanks for your concern about this case. I tried to create a sample data myself based on the user's requirement and implemented the result. Please check if there is anything that can be improved. Here is my solution:

    Here are the steps you can follow:

    1. Create calculated column.

     

    Week = WEEKNUM('Table'[Date],1)
    Month =
    MONTH('Table'[Date])
    Year = YEAR('Table'[Date])
    Date_format =
     DATE(
        YEAR([Date]),MONTH([Date]),DAY([Date]))

     

    2. Create calculated table -- Slicer.

     

    Table 2 =
    DISTINCT('Table'[Date_format])

     

    3. Modeling – New parameter –Fields.

    4. Create measure.

     

    Flag =
    var _date=
    SELECTCOLUMNS('Table 2',"date",'Table 2'[Date_format])
    var _week=
    SELECTCOLUMNS(FILTER(ALL('Table 2'),'Table 2'[Date_format] in _date),"week",WEEKNUM('Table 2'[Date_format],2))
    var _count=
    COUNTX(ALLSELECTED('Table 2'),'Table 2'[Date_format])
    var _select=SELECTEDVALUE('Parameter'[Parameter Fields])
    return
    SWITCH(
        TRUE(),
      CONTAINSSTRING(_select,"Date")=TRUE()&&_count<=2 &&MAX('Table'[Date_format]) in _date,1,
      CONTAINSSTRING(_select,"Week")=TRUE()&&WEEKNUM(MAX('Table'[Date]),2) in _week ,1,0)

     

    5. Treat Parameter[Parameter] as the x-axis of the slicer and the line graph, respectively.

    6. Place [Flag]in Filters, set is=1, apply filter.

    7. Result:

    Slicer Date_format :select tow dates Slicer Parameter: select week.

    Click Drill Down on the visual:

    Slicer Date_format :select multiple dates Slicer Parameter: select week.

    Click Drill Down on the visual:

     

    Best Regards,

    Liu Yang

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