cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
yve214
Helper II
Helper II

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
tomfox
Resident Rockstar
Resident Rockstar

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/

View solution in original post

4 REPLIES 4
yve214
Helper II
Helper II

@tomfox ,

 

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 II
Helper II

@tomfox ,

 

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 @tomfox '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.

tomfox
Resident Rockstar
Resident Rockstar

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/

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors