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
j_martinho
Helper I
Helper I

Sum total column values from the last 14 days

Hello!

 

I'm trying to create a new column (DAX or PowerQuery) so that it adds the value of the Cases column for the last 14 days.

The sum must take into account the CityCode. Thus, adding the last 14 days for each CityCode.

Can you help me?

 

Data example:

DateCasesCityCodeTotal Cases Last 14 days
10/08/202030125329737
09/08/202012335326725
08/08/202019215325492
07/08/202019035323571
06/08/202020345321668
05/08/202020425319634
04/08/202018805317592
03/08/202020165315712
02/08/202021065313696
01/08/202016305311590
31/07/20201850539960
30/07/20202100538110
29/07/20201616536010
28/07/20202246534394
27/07/20202148532148
10/08/202040121144737
09/08/202022331140725
08/08/202029211138492
07/08/202029031135571
06/08/202030341132668
05/08/202030421129634
04/08/202028801126592
03/08/202030161123712
02/08/202031061120696
01/08/202026301117590
31/07/202028501114960
30/07/202031001112110
29/07/20202616119010
28/07/20203246116394
27/07/20203148113148
1 ACCEPTED SOLUTION

@amitchandak I made two adjustments and solved it. Thank you!

 

 

Casos Ativos = 

sumx(
    filter(NOVO_PROTO,
            NOVO_PROTO[city_ibge_code] = earlier( NOVO_PROTO[city_ibge_code] )
             && NOVO_PROTO[Data] <= earlier( NOVO_PROTO[Data] )
             && NOVO_PROTO[Data] >= earlier( NOVO_PROTO[Data] )-13),

    NOVO_PROTO[Novos Confirmados])

 

View solution in original post

4 REPLIES 4
v-diye-msft
Community Support
Community Support

Hi @j_martinho 

 

Would you like to get the sum results of [Total Cases Last 14 days] by [Citycode]? You can try below calculated column:

Column = CALCULATE(SUM('Table (2)'[Total Cases Last 14 days]),FILTER(ALL('Table (2)'),[CityCode]=EARLIER('Table (2)'[CityCode])))

 

If not help. please kindly elaborate more.

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
amitchandak
Super User
Super User

@j_martinho , Try a new column

sumx(filter(Table, [CityCode] = earlier( [CityCode] ) && [CityCode] <= earlier( [Date] ) && [CityCode] >= earlier( [Date] )-14),[Total Cases])

@amitchandak I made two adjustments and solved it. Thank you!

 

 

Casos Ativos = 

sumx(
    filter(NOVO_PROTO,
            NOVO_PROTO[city_ibge_code] = earlier( NOVO_PROTO[city_ibge_code] )
             && NOVO_PROTO[Data] <= earlier( NOVO_PROTO[Data] )
             && NOVO_PROTO[Data] >= earlier( NOVO_PROTO[Data] )-13),

    NOVO_PROTO[Novos Confirmados])

 

@amitchandak Thank you. But the column went blank.

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