Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
yve214
Helper III
Helper III

How to get an aggregated value for each week

Hi Guys I have a problem I am unable to solve.

 

I am trying to get an aggregated value for the week that is monday - sunday. 

How am I able to aggregate it so it shows just for the last day of the week.

 

sample table:

 

Assuming by week is Monday - Sunday. Please I want to aggregate all quantities for each week and show it on the weekend date (Sunday of each week which is the max date)

 

CategoryDateQtyExpected result

a

1/3/2022100-
a

1/4/2022

150-
a

1/5/2022

50-
a

1/6/2022

300-
a1/7/2022100-
a1/8/202225-
a1/9/20220725
1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @yve214 ,

 

How about this:

tomfox_1-1652474029882.png

 

Here the DAX code for the measure:

WeekTotalMeasure = 
VAR _currentWeek = WEEKNUM (  MAX ( Table[Date] ), 2 )
RETURN
IF (
    WEEKDAY ( MAX ( Table[Date] ), 2) = 7,
    CALCULATE (
        SUM ( Table[Qty] ),
        ALL ( Table),
        WEEKNUM ( Table[Date] ) = _currentWeek
    ), 
    BLANK()
)

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

4 REPLIES 4
yve214
Helper III
Helper III

@tackytechtom ,

 

Thank you very much. It worked, I think I was using the wrong date table so it was giving me different aggregates.

 

@Icey thank you so much for verifying. I had to look at the query again with a fresh pair of eyes

yve214
Helper III
Helper III

@tackytechtom ,

 

Thank you so much for your help. I was able to get an aggregated sum for sundays but it wasnt the actual sum for each week (monday through sunday). Please what can I adjust?

 

CategoryDateQtyExpected result

a

1/3/2022100-
a

1/4/2022

150-
a

1/5/2022

50-
a

1/6/2022

300-
a1/7/2022100-
a1/8/202225-
a1/9/20220725
a1/10/2022101-
a1/11/202285-
a1/12/2022100-
a1/13/2022150 
a1/14/2022100-
a1/15/202255-
a1/16/20220591

 

Icey
Community Support
Community Support

Hi @yve214 ,

 

Have you created a measure, not a column, based on @tackytechtom 's expression? Based on my test, it can give you the expected result.

Icey_0-1652862427482.png

 

 

Best Regards,

Icey

 

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

tackytechtom
Super User
Super User

Hi @yve214 ,

 

How about this:

tomfox_1-1652474029882.png

 

Here the DAX code for the measure:

WeekTotalMeasure = 
VAR _currentWeek = WEEKNUM (  MAX ( Table[Date] ), 2 )
RETURN
IF (
    WEEKDAY ( MAX ( Table[Date] ), 2) = 7,
    CALCULATE (
        SUM ( Table[Qty] ),
        ALL ( Table),
        WEEKNUM ( Table[Date] ) = _currentWeek
    ), 
    BLANK()
)

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors