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

Calculate value for one month but have the value for each month

Hi 

 

I have data for 13 months and i have a date table and a data table. They are connected by date keyes. 

I then have a slicer where i choose the last 12 weeks. I would then like to calculate the sum of sales in week 1 and calculate the ratio for eacg sale in the other 11 week. 

 

I calculate the sale for week 1 as 

 

Salesweek1 = 

SUMX(
FILTER( KEEPFILTERS(Dim_Date) ,
Dim_Date[Is12WeeksAgo] = 1 ),
[Total Sales])
 
But this give back a value for all the weeks in data and not only the 12 last weeks.
 
I found a example of it in Microsoft page for the definition of calculate table. Which show what i need as output but it is not possible for me. 
 

Can anybody help me? 

 

Skærmbillede 2020-12-04 151948.png

 

 

 

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @Snip  ,

According to your description, create data from January 1, 2020 to April 1, 2020:

v-yangliu-msft_0-1607418125187.png

Here are the steps you can follow:

1. Create calculate table.

week of year = WEEKNUM('Table'[Date],1)

2. Create measure.

first_week =
var _1=SELECTEDVALUE('Date'[Date])
var _once=CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),WEEKNUM(_1)='Table'[week of year]))
return IF(MAX('Table'[week of year])<>WEEKNUM(_1),BLANK(),_once)
_two_twifth_ ratio for eacg =
var _1=SELECTEDVALUE('Date'[Date])
var _two_twelfth=CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),'Table'[week of year]>=WEEKNUM(_1)+1&&'Table'[week of year]<=WEEKNUM(_1)+11))
var _total = CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(MAX('Table'[Date]))))
return
IF(MAX('Table'[week of year])=WEEKNUM(_1),BLANK(),DIVIDE(_two_twelfth,_total))

3. Result

v-yangliu-msft_1-1607418125193.jpeg

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

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

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.