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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
RSSILVA_22
Helper I
Helper I

measure to sum the result of the current week (of the current month).

I need to create a measure to add values ​​for the last week, but within the same month.

I made the measurement below, but it is taking from 11/29/2021 until 12/05/2021.

I need her to return the week within the current month (12/01/2021 to 12/05/2021)

 

Can you help me?

 

gross_na_semana =
VAR _selectedDate =
MAX ( tb_gross_agencias_correios[data_atendimento] )
VAR _endOfWeekDate =
_selectedDate + 7
- WEEKDAY ( _selectedDate, 2 )
VAR lastMonday =
CALCULATE (
MAX ( tb_gross_agencias_correios[data_atendimento] ),
FILTER (
ALL ( tb_gross_agencias_correios[data_atendimento] ),
tb_gross_agencias_correios[data_atendimento] <= _selecteddate
&& WEEKDAY ( tb_gross_agencias_correios[data_atendimento] ) = 2
)
)
RETURN
CALCULATE (
DIVIDE(SUM(tb_gross_agencias_correios[qtda]),[Total DUs Parcial],0),tb_gross_agencias_correios[servico]="Gross Adds",tb_gross_agencias_correios[status_atendimento]="F",
FILTER (
ALL ( tb_gross_agencias_correios[data_atendimento] ),
tb_gross_agencias_correios[data_atendimento] <= _endOfWeekDate
&& tb_gross_agencias_correios[data_atendimento] >= lastMonday
)
)
1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @RSSILVA_22 

 

Please try this Measure.

 

gross_na_semana =

VAR _selectedDate =

    MAX ( tb_gross_agencias_correios[data_atendimento] )

VAR _endOfWeekDate =

    _selectedDate + 7

        - WEEKDAY ( _selectedDate, 2 )

VAR lastMonday =

    CALCULATE (

        MIN( tb_gross_agencias_correios[data_atendimento] ),

        FILTER (

            ALL ( tb_gross_agencias_correios[data_atendimento] ),

            tb_gross_agencias_correios[data_atendimento] <= _selecteddate

                && tb_gross_agencias_correios[data_atendimento]>_endOfWeekDate-7

                && MONTH ( tb_gross_agencias_correios[data_atendimento] ) = MONTH ( _selectedDate )

        )

    )

RETURN

   CALCULATE (

        DIVIDE ( SUM ( tb_gross_agencias_correios[qtda] ), [Total DUs Parcial], 0 ),

        tb_gross_agencias_correios[servico] = "Gross Adds",

        tb_gross_agencias_correios[status_atendimento] = "F",

        FILTER (

            ALL ( tb_gross_agencias_correios[data_atendimento] ),

            tb_gross_agencias_correios[data_atendimento] <= _endOfWeekDate

                && tb_gross_agencias_correios[data_atendimento] >= lastMonday

        )

    )

 

Best Regards,

Community Support Team _ Caiyun

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. If you still have problems on it or I misunderstand your needs, please feel free to let us know. Thanks a lot!

View solution in original post

2 REPLIES 2
v-cazheng-msft
Community Support
Community Support

Hi @RSSILVA_22 

 

Please try this Measure.

 

gross_na_semana =

VAR _selectedDate =

    MAX ( tb_gross_agencias_correios[data_atendimento] )

VAR _endOfWeekDate =

    _selectedDate + 7

        - WEEKDAY ( _selectedDate, 2 )

VAR lastMonday =

    CALCULATE (

        MIN( tb_gross_agencias_correios[data_atendimento] ),

        FILTER (

            ALL ( tb_gross_agencias_correios[data_atendimento] ),

            tb_gross_agencias_correios[data_atendimento] <= _selecteddate

                && tb_gross_agencias_correios[data_atendimento]>_endOfWeekDate-7

                && MONTH ( tb_gross_agencias_correios[data_atendimento] ) = MONTH ( _selectedDate )

        )

    )

RETURN

   CALCULATE (

        DIVIDE ( SUM ( tb_gross_agencias_correios[qtda] ), [Total DUs Parcial], 0 ),

        tb_gross_agencias_correios[servico] = "Gross Adds",

        tb_gross_agencias_correios[status_atendimento] = "F",

        FILTER (

            ALL ( tb_gross_agencias_correios[data_atendimento] ),

            tb_gross_agencias_correios[data_atendimento] <= _endOfWeekDate

                && tb_gross_agencias_correios[data_atendimento] >= lastMonday

        )

    )

 

Best Regards,

Community Support Team _ Caiyun

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. If you still have problems on it or I misunderstand your needs, please feel free to let us know. Thanks a lot!

amitchandak
Super User
Super User

@RSSILVA_22 , Last week within same moth

 

Last Week =
var _max = maxx(allselected('Date'), 'Date'[Date])
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1 && eomonth('Date'[Date],0) - eomonth(_max,0) ))

 

But what will happen when this first week of month ?

 

new columns in date table

 

new columns
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
Week = WEEKNUM([Date],2)
year Week = if('Date'[Week Number]<10,'Date'[Year]*10 & 'Date'[Week Number],'Date'[Year]&'Date'[Week Number])
OR
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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