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
Anonymous
Not applicable

How to count values in a report by dates and display them on a chart in weeks

Hi,

 

I have two table Calendar and Purchases.

Calendar:

DateWeek of Year
2020-01-011
2020-01-021
......
2020-12-3153

 

Purchases:

IDTitleStart of purchaseEnd of purchase
1Monitors2020-01-102020-02-16
2Laptops2020-02-012020-03-05

 

How can I show in the report in which weeks and how much purchases were in progress?

The week in which the purchase was completed shall not be included in that week.

For example, I need to see in report:

Purchases by weeks.png

 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous ,

 

According to your description, I created some data to show:

v-yangliu-msft_0-1605229292900.png

 

Here are the steps you can follow:

1. Create calculated column.

Start_week = WEEKNUM('Table'[Start of purchase],1)
End_week = WEEKNUM('Table'[End of purchase],1)

2. Create calculated column.

Number of purchases =
var _time=
CALCULATE(COUNT('Table'[Title]),FILTER('Table','Week Of Year'[Week of Year]>='Table'[Start_week]&&'Week Of Year'[Week of Year]<='Table'[End_week]))

return IF(_time=BLANK(),0,_time)

3. Result.

v-yangliu-msft_1-1605229292904.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.

View solution in original post

7 REPLIES 7
v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous ,

 

According to your description, I created some data to show:

v-yangliu-msft_0-1605229292900.png

 

Here are the steps you can follow:

1. Create calculated column.

Start_week = WEEKNUM('Table'[Start of purchase],1)
End_week = WEEKNUM('Table'[End of purchase],1)

2. Create calculated column.

Number of purchases =
var _time=
CALCULATE(COUNT('Table'[Title]),FILTER('Table','Week Of Year'[Week of Year]>='Table'[Start_week]&&'Week Of Year'[Week of Year]<='Table'[End_week]))

return IF(_time=BLANK(),0,_time)

3. Result.

v-yangliu-msft_1-1605229292904.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.

ryan_mayu
Super User
Super User

@Anonymous 

please see the attachment. Hope this is helpful.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

@ryan_mayu , hi, thank you.

Everything looks good, but if the purchase doesn’t have an end date, the report doesn’t count it. Such a purchase must be in progress (today he is in progress). Can you update the COUNT formula? Thank you.

@Anonymous 

maybe you can try this

COUNT = 
CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[start of purchased]<='calendar'[Date]&&('Table'[End of purchased]>='calendar'[Date]&&WEEKNUM('Table'[End of purchased],2)<>'calendar'[week of year]||ISBLANK('Table'[End of purchased]))))




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

@ryan_mayu That formula doesn't work well. The number of ongoing purchases has increased. Past and future purchases are also displayed. It's not good 😕 

Anonymous
Not applicable

@amitchandak , I am not a professional, maybe you can detail the formulas according to my example? Because I can't relate your example to my example. 

amitchandak
Super User
Super User

@Anonymous , refer if this attached file can replace

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.