Forum Discussion

mb0307's avatar
mb0307
Responsive Resident
6 years ago
Solved

Weekly data into monthly format

Hi all,

 

I want to summarise Weekly data into Month format.

 

I do not have Day/Date level information in the table.  Data only comes in Weekly format so having a calendar table might not solve the issue. 

 

JULY 2020 Calendar:

WEEKMonTueWedThuFriSatSun
27293012345
286789101112
2913141516171819
3020212223242526
31272829303112

 

Week 27 and 31 spread into two months.

 

I want to sum [SALES] numbers for July but ignoring Non-July days (in gray).  I want to apply this to all the months in any given year.

 

Eg data:

NOTEWeekSales
Source data has no date field27100
Source data has no date field27200
Source data has no date field27200
Source data has no date field301000
Source data has no date field301000
Source data has no date field3150
Source data has no date field3150
Source data has no date field31100

 

 

Output:

WeekWeekSales SumSales Sum * (5/7 days of week)Result 
27500357.1Week 27 has 5 days in July and 2 in June so Sales sum for JULY should only incl 5 days.  I guess in absence of DATE field in the source data, the percentage of 5days (5/7 days of a week) can be used to multiple by Sales to complete montly sum
3020002000Entire week is in July
31200142.95 days in July and 2 in Aug so Sales sum for JULY should only incl 5 days

 

Please let me know if this can be achieved using DAX.

 

Thanks in advance.

  • Hi, mb0307 

    You may check if the sample file helps.

    pbix. attached

    If it meets your requirement,please follow these step:

    1.create calcualted column in original table:

     

    Sum sales this week = CALCULATE(SUM('Original Table'[Sales]),ALLEXCEPT('Original Table','Original Table'[Year],'Original Table'[Week]))
    Average daily sales this week = 'Original Table'[Sum sales this week]/7

     

    2.Then create a new table with calendar date

     

    New table with Calendar = CALENDAR(DATE(2019,01,01),DATE(2020,12,30))

     

    Add new calculated  columns:

     

    WeekNum = WEEKNUM('New table with Calendar'[Date],2)
    average daily sales = 
    var a =CALCULATE(MAX('Original Table'[Average daily sales this week]),FILTER('Original Table','Original Table'[Week]='New table with Calendar'[WeekNum]))
    return IF(ISBLANK(a),0,a)

     

    Apply the filelds to  table visualization  and the result will show as below:

     

    Best Regards,
    Community Support Team _ Eason
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

    • mb0307's avatar
      mb0307
      Responsive Resident

      AllisonKennedy  Please see my original pot.  I have added more info.  Thank you.

       

      amitchandak  I will try your method.  But first formula throwing this error: Too few arguments were passed to the DATE function. The minimum argument count for the function is 3.

      • v-easonf-msft's avatar
        v-easonf-msft
        Community Support

        Hi, mb0307 

        You may check if the sample file helps.

        pbix. attached

        If it meets your requirement,please follow these step:

        1.create calcualted column in original table:

         

        Sum sales this week = CALCULATE(SUM('Original Table'[Sales]),ALLEXCEPT('Original Table','Original Table'[Year],'Original Table'[Week]))
        Average daily sales this week = 'Original Table'[Sum sales this week]/7

         

        2.Then create a new table with calendar date

         

        New table with Calendar = CALENDAR(DATE(2019,01,01),DATE(2020,12,30))

         

        Add new calculated  columns:

         

        WeekNum = WEEKNUM('New table with Calendar'[Date],2)
        average daily sales = 
        var a =CALCULATE(MAX('Original Table'[Average daily sales this week]),FILTER('Original Table','Original Table'[Week]='New table with Calendar'[WeekNum]))
        return IF(ISBLANK(a),0,a)

         

        Apply the filelds to  table visualization  and the result will show as below:

         

        Best Regards,
        Community Support Team _ Eason
        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • mb0307 , from week you can get week start date like this

     

    date = date([year],[Week No]*7 -Weekday(date([year],1,1)))

     

    This was with format YYYY WW

    Weektodate = date(RIGHT(Table[Week Format],4),1,1)+(mid(Table[Week Format],5,SEARCH(" ",Table[Week Format])-5 )*7) - (WEEKDAY(date(RIGHT(Table[Week Format],4),1,1)))

     

    once you have a date you can manage with date dimension. Across month you need split data