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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
ivasgal
New Member

Weekly Calculation Based on Date Filter

Hello Experts,

 

I am new to Power BI and I'm struggling on creating a measurement that calculates how many inspections were done in the week based on what date the user selects in a slicer. 

 

I have 2 tables:

- DataDump Table (where all my entries are)
- Date Week Table (calendar table)

 

I have a slicer which shows dates from my Date Week Table, the user selects what day they want to see data from, then my visuals pull the data from my DataDump table for that day.

 

What I need is a measure that calculates how many inspections were or have been done in that week of the day selected. 

For example if user selects 01/05/2022, I want a measure that shows inspections done from 01/03/2022-01/09/2022

 

DataDump Table

ivasgal_0-1644599955177.png

 

Date Week Table

ivasgal_1-1644599994932.png

 

Date Slicer

ivasgal_3-1644600111757.png

 

I have this other calculation where it shows how many inspection done in the date range selected by user. On 01/05/2022 a total of 354 inspections were done

ivasgal_5-1644600268364.png

 

This is the formula I have for the measure above

ivasgal_6-1644600338449.png

 

Here is where I want to show the result. For this selection the result should be: 1607 inspections done for the week of 01/03/22-01/09/22

ivasgal_4-1644600130396.png

 

I just can't figure out how to do the formula to do what I need it to do. Hopefully I explained myself.

 

I appreciate the help!

 

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

Hi @ivasgal ,

 

Make sure the relationship between DataDump Table and Date Week Table is inactive.

You have weeknumber in the date week table so you could create a measure as below:

measure = calculate(counta(DataDump[rows]),filter(allselected(DataDump),weeknum(DataDump[inspections date],2) = selectedvalue(Date Week[week])))

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

2 REPLIES 2
v-jayw-msft
Community Support
Community Support

Hi @ivasgal ,

 

Make sure the relationship between DataDump Table and Date Week Table is inactive.

You have weeknumber in the date week table so you could create a measure as below:

measure = calculate(counta(DataDump[rows]),filter(allselected(DataDump),weeknum(DataDump[inspections date],2) = selectedvalue(Date Week[week])))

 

Best Regards,

Jay

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

@ivasgal , Have week rank column in you date/week tbale

 

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)
OR
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

then try measures

This Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.